Created
October 8, 2020 05:44
-
-
Save kmwalsh/b2a6e10b28993c5b421581adb8ca9be7 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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