Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active March 20, 2024 20:38
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 sybrew/ad17b0593116a5d7e3c8706f7cac1986 to your computer and use it in GitHub Desktop.
Save sybrew/ad17b0593116a5d7e3c8706f7cac1986 to your computer and use it in GitHub Desktop.
Sets noindex if post has term from CPT taxonomy 'partner'.
<?php
// Do not include the PHP opening tag if PHP is already open.
// For: https://wordpress.org/support/topic/no-index-custom-post-type-specific-taxonomy/
// TSF 5.0+
add_filter(
'the_seo_framework_robots_meta_array',
function ( $meta, $args ) {
if ( null === $args ) {
$tsfquery = tsf()->query();
if ( $tsfquery->is_singular() )
$post_id = $tsfquery->get_the_real_id();
} else {
if ( 'single' === \The_SEO_Framework\get_query_type_from_args( $args ) ) {
$post_id = $args['id'];
}
}
if ( ! empty( $post_id ) && has_term( 286, 'partner', $post_id ) )
$meta['noindex'] = 'noindex';
return $meta;
},
10,
2,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment