Why exit() AND exit in these two code snippets?
-
This function uses exit();
function redirect_cpt_archive() { if( is_post_type_archive( 'YOUR-CUSTOM-POST-TYPE' ) ) { wp_redirect( home_url( 'YOUR-TRAILING-SLUG' ), 301 ); exit(); } } add_action( 'template_redirect', 'redirect_cpt_archive' );
This function uses exit – no parentheses
add_action( 'template_redirect', 'redirect_post_type_single' ); function redirect_post_type_single(){ if ( ! is_singular( 'YOUR-CUSTOM-POST-TYPE' ) ) return; wp_redirect( get_page_link( YOUR-PAGE-ID ), 301 ); exit; }
WHY? What’s the difference?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Why exit() AND exit in these two code snippets?’ is closed to new replies.