Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save doitonlinemedia/ea1c295d378ec1ca4e7a81dd22e80763 to your computer and use it in GitHub Desktop.
Save doitonlinemedia/ea1c295d378ec1ca4e7a81dd22e80763 to your computer and use it in GitHub Desktop.
Redirect CTP single to CPT archive, Add noindex, nofollow to CPT single.
/**
* 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