user3697526
user3697526

Reputation: 37

Set noindex nofollow on posts from multiple categories using Yoast WordPress SEO

This Wordpress filter sets noindex nofollow for a single category, but how would I do the same for multiple categories, for example, if I wanted to noindex nofollow category1, category2, category3, etc

add_filter( 'wpseo_robots', 'yoast_seo_robots_remove_single' );
/**
 * Set certain posts to noindex nofollow
 */
function yoast_seo_robots_remove_single( $robots ) {

    if ( is_single() && has_term( 'category1', 'category' ) ) { 
    return 'noindex,nofollow'; 
} 

else {
    return $robots; 
     }
}

Upvotes: 1

Views: 531

Answers (0)

Related Questions