SEO PHP Beginner

Noindex Date, Author and Thin Archive Pages

Tell search engines not to index date archives, author archives on single-author sites and empty tag pages, using WordPress's robots API.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 24 lines
add_filter( 'wp_robots', function ( array $robots ): array {
	$noindex = false;

	// Date archives (/2026/11/) usually duplicate your normal archives.
	if ( is_date() ) {
		$noindex = true;
	}

	// Author archives duplicate the blog on sites with only one author.
	if ( is_author() && count( get_users( [ 'capability' => 'edit_posts', 'has_published_posts' => true, 'fields' => 'ID', 'number' => 2 ] ) ) < 2 ) {
		$noindex = true;
	}

	// Tag pages with fewer than 3 posts are thin.
	if ( is_tag() && get_queried_object()->count < 3 ) {
		$noindex = true;
	}

	if ( $noindex ) {
		$robots['noindex'] = true;
		$robots['follow']  = true;
	}
	return $robots;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Don't use with An SEO plugin with its own noindex settings. Check the notes below before adding it.

WordPress creates archive pages for every date, author and tag. Many of them repeat the same posts as your main blog pages or list just one or two posts. This snippet tells search engines not to index those, while still following their links.

How it works

Since version 5.7, WordPress builds the robots meta tag through the wp_robots filter. The snippet adds noindex, follow to:

  • Date archives, such as /2026/11/.
  • Author archives, but only when the site has fewer than two authors with published posts.
  • Tag archives with fewer than three posts.

The previous version printed its own robots tag, which created a second, conflicting tag next to the one WordPress already prints. It also noindexed search results, which WordPress already does by itself, and paginated archives like /page/2/. Google no longer recommends noindexing paginated pages, because they’re how crawlers find your older posts.

Things to watch

  • SEO plugins have their own settings for these archives. Use those instead if you have one.
  • Change the tag threshold of 3 to suit how you use tags.
  • Noindexed pages drop out of search results over a few weeks, not instantly.

How to test it

Open a date archive such as yoursite.com/2026/, view the source and search for name='robots'. You should see one tag containing noindex, follow. A normal category page should not have it.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only