-
-
Save jeweltheme/1aa535d1d211be91e223eb909ad96699 to your computer and use it in GitHub Desktop.
WordPress: Template redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In functions.php | |
add_action( 'template_redirect', 'redirect_template' ); | |
function redirect_template() { | |
global $post; | |
if ( is_single() && is_post_type( 'custompost' ) ) { | |
wp_redirect( home_url() . '/custompost/' ); | |
exit; | |
} | |
} | |
function is_post_type( $type ) { | |
global $wp_query; | |
if( $type == get_post_type( $wp_query->post->ID ) ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment