Skip to content

Instantly share code, notes, and snippets.

@kmwalsh
Created October 8, 2020 05:44
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 kmwalsh/b2a6e10b28993c5b421581adb8ca9be7 to your computer and use it in GitHub Desktop.
Save kmwalsh/b2a6e10b28993c5b421581adb8ca9be7 to your computer and use it in GitHub Desktop.
/**
* Redirect single of CPT to page
*/
if ( ! function_exists('kw_redirect_resource') ) {
add_action( 'template_redirect', 'kw_redirect_resource' );
function shnj_redirect_resource() {
if ( is_singular( 'CUSTOM_POST_TYPE_NAME' ) ) :
//get the url by path
$url = get_permalink( get_page_by_path( 'PAGE_PATH_TO_REDIRECT' ) );
//always escape
wp_redirect( esc_url( $url ), 301 );
exit;
endif;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment