Noindex Posts Below a Word Count
Adds noindex to blog posts with fewer words than a minimum, such as quick updates or link posts, so thin pages do not drag down how search engines see your site.
Opens WPIDE on
Code
// Post types checked and the minimum number of words.
$wpide_thin_types = array( 'post' );
$wpide_thin_min_words = 250;
add_filter( 'wp_robots', function ( $robots ) use ( $wpide_thin_types, $wpide_thin_min_words ) {
if ( ! is_singular( $wpide_thin_types ) ) {
return $robots;
}
$content = (string) get_post_field( 'post_content', get_queried_object_id() );
$words = str_word_count( wp_strip_all_tags( strip_shortcodes( $content ) ) );
if ( $words < $wpide_thin_min_words ) {
$robots['noindex'] = true;
$robots['follow'] = true;
}
return $robots;
} );
Notes
Change the post types and minimum. The count ignores HTML and shortcodes.
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.