Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.