Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeweltheme/1aa535d1d211be91e223eb909ad96699 to your computer and use it in GitHub Desktop.
Save jeweltheme/1aa535d1d211be91e223eb909ad96699 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