Few Lines to Avoid Duplicate Content With WordPress

Standard

Because I’m a little paranoid about duplicate content, I learned a little about how WP works to create a solution to avoid this. I now share with you the solution that I created and I use with this blog.

I read much about how Google deals with WP and duplicate content, and there are many recommendations. One side, some of them explain that Google knows how WP works and does not sanction the latter, and on another side some explain the opposite…

Therefore, If like me you want to be sure that there is no duplicate content or if you just want to see your posts/pages indexed and nothing else (like tags/categories), then put these followed lines between the <head> tag into the header.php file:

if((is_home() && ($paged < 2 )) || is_single() || is_page())
    echo '<meta name="robots" content="index, follow" />';
else
    echo '<meta name="robots" content="noindex, follow" />';

As you can see this is quite simple. If the current page is the home page, a post or a page, we indicate to Google that it can add this content to its index. Otherwise, we indicate it to follow the link which it can find, without add the current page to the index.

Lastly, I recommend you to look at the Function Reference to know more functions like is_tag(), is_archive() etc.

About Gaëtan Masson

I'm a French student in computer science, passionate about programming, computing and more broadly by new technologies. I've written this blog in English to reach more people, but also to train my language. If a sentence/word looks strange to you don't hesitate to correct me.

  • Shelob9

    Cool snippet. I’m wondering why you are not only adding nofollow to $paged > 2 ? I guess I don’t see what the concern is about any other type of page.

    • http://gaetanmasson.com/ Gaëtan Masson

      I always let the “follow” to allow to Google to continue its crawling regardless where it is.