Noindex Category and Tag Pages With Few Posts
Adds noindex to category, tag and custom taxonomy archives that hold fewer posts than a minimum, so near-empty pages do not dilute your search presence.
Opens WPIDE on
Code
// Archives with fewer posts than this get noindex.
$wpide_min_term_posts = 3;
add_filter( 'wp_robots', function ( $robots ) use ( $wpide_min_term_posts ) {
if ( is_category() || is_tag() || is_tax() ) {
$term = get_queried_object();
if ( $term instanceof WP_Term && (int) $term->count < $wpide_min_term_posts ) {
$robots['noindex'] = true;
$robots['follow'] = true;
}
}
return $robots;
} );
Notes
Change the minimum number of posts at the top. The pages start being indexed again once they reach it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.