SEO

Stop Search Engines From Indexing Search Results

Keywords

On your search pages of your WordPress you want to make sure that these are not indexed by the search engines. Having these indexed might create duplicate entries in the search engines compared to your category or archive pages.

Here is a quick WordPress snippet to stop the search engines from indexing these pages, add the following into the head tag of theme.

<?php if(is_search()) { ?>
   <meta name="robots" content="noindex, nofollow" />
<?php }?>

This uses the is_search function which will return true if you are on the search page.

Then we can add a meta tag which will tell the search engines if you do land on this page don't index the page and don't follow any of the links of the page. Having both these in the meta robots tag will mean that the crawler will not go over the page and will crawl the next page.

Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial