Skip to content

Instantly share code, notes, and snippets.

@wwdboer
Last active May 17, 2017 04:34
Show Gist options
  • Save wwdboer/4353695 to your computer and use it in GitHub Desktop.
Save wwdboer/4353695 to your computer and use it in GitHub Desktop.
WordPress: Template redirect
<?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