Created
February 21, 2019 08:47
-
-
Save doitonlinemedia/ea1c295d378ec1ca4e7a81dd22e80763 to your computer and use it in GitHub Desktop.
Redirect CTP single to CPT archive, Add noindex, nofollow to CPT single.
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
/** | |
* Redirect CTP single to CPT archive. | |
*/ | |
function dom_single_redirect_post() { | |
$queried_post_type = get_query_var('post_type'); | |
if ( | |
is_single() && 'team' == $queried_post_type || | |
is_single() && 'kranten' == $queried_post_type || | |
is_single() && 'klanten' == $queried_post_type || | |
is_single() && 'geschiedenis' == $queried_post_type | |
) { | |
wp_redirect( get_post_type_archive_link($queried_post_type), 301 ); | |
exit; | |
} | |
} | |
add_action( 'template_redirect', 'dom_single_redirect_post' ); | |
/** | |
* Add noindex, nofollow to CPT single. | |
*/ | |
add_filter( 'the_seo_framework_robots_meta_array', function( $meta ) { | |
if ( is_singular( array( 'team', 'kranten', 'klanten', 'geschiedenis' ) ) ) { | |
if ( the_seo_framework() ) { | |
$meta['noindex'] = 'noindex'; | |
$meta['nofollow'] = 'nofollow'; | |
} | |
} | |
return $meta; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment