Read my latest blog entry: Does your web site help, or hurt your business?.
Subscribe to my RSS Feed or by Email.
  • Home
  • About
  • Services
  • Blog
  • Contact
Christopher Ross Building better web sites, one pixel at a time.

Fixing Duplicate Content So Google doesn’T See It.


Welcome to my blog, please feel free to subscribe to my RSS feed or leave a comment.

There are a lot of blogs you’ll find with an invaluable code snippet designed to ensure Google only indexes the posts on your web site and does not duplicate the categories and tags pages, unfortunately the code they’re using has a critical flaw as you’ll see by viewing my Google Webmasters Tool report to the right. Even using the tool, I keep getting duplicate content notifications.

The code is here:

<?php if(is_home() || is_single() || is_page()){
echo ‘<meta name=”robots” content=”index,follow”>’;
} else {
echo ‘<meta name=”robots” content=”noindex,follow”>’;
}?>

You can find it on a ton of blogs:

  • like here
  • or here
  • even here
It places the <meta name=”robots” content=”noindex,follow”> code on any page which is not your home page, a content page or post page. On those pages it places <meta name=”robots” content=”index,follow”> which tells robots to crawl the page to be included in their database. This is great except, what happens when you create a post that’s in two categories on your web site?
My post, Meta Tags that Kill Your Blog is found at:
  1. http://www.thisismyurl.com/wordpress/meta-tags-that-kill-your-blog/ and;
  2. http://www.thisismyurl.com/web-advice/meta-tags-that-kill-your-blog/
Google is counting this page twice and will most likely assume that I’m trying to pull a fast one on the robot when in fact, I’m simply trying to help users by listing the content in two categories. The solution? We have to tell Google to ignore one of the two posts.
To accomplish this, we need to first edit the earlier code sample to give us a place to add our new code:
  

if(is_home()) {echo ‘<meta name=”robots” content=”index,follow” />’; }
elseif(is_page()) {echo ‘<meta name=”robots” content=”index,follow” />’; }
elseif(is_single()) {
} else { echo ‘<meta name=”robots” content=”noindex,follow” />’; }

 

Now we know that we’re on a single (that’s a post) so we can test to see if content is unique. I struggled with how to do this but finally decided that the first category would have to be the most important category, hopefully that’s the best way but I’m always open to suggestions.
  

$category = get_the_category();
if(strpos($_SERVER['REQUEST_URI'],$category[0]->category_nicename.”/”)>0) {
echo ‘<meta name=”robots” content=”index,follow” />’;
} else {
echo ‘<meta name=”robots” content=”noindex,follow” />’;
}
What I’ve done is tested to see if this is the first category ($category[0]) and checked it’s nice_name against the current URL. If we’re on the URL of the first category … we tell Google to index our content, otherwise we tell it to ignore our content. I’m sure that I’ll have to fix this at a later date but it’s worked so far. If you have a better way to do it, let me know.
Here’s the final code:
if(is_home()) {echo ‘<meta name=”robots” content=”index,follow” />’; }
elseif(is_page()) {echo ‘<meta name=”robots” content=”index,follow” />’; }
elseif(is_single()) {
$category = get_the_category();
if(strpos($_SERVER['REQUEST_URI'],$category[0]->category_nicename.”/”)>0) {
echo ‘<meta name=”robots” content=”index,follow” />’;
} else {
echo ‘<meta name=”robots” content=”noindex,follow” />’;
}
} else { echo ‘<meta name=”robots” content=”noindex,follow” />’; }

Other Posts of Interest

  • Bloody Mess of a WordPress Theme
  • Blog Roundup for October 23rd
  • Blog Roundup for October 22nd
  • Blog Round Up - October 18th
  • WordPress Magazine Theme - Free Dark Version
  • Smashingly Good Free Magazine Theme for WordPress
  • Simple tricks to speed up your WordPress web site.
  • Five Free SEO WordPress Themes in Five Days
  • Search Engine Optimization Techniques for WordPress
  • Blog Roundup for the 14th of October 2008
Posted on: Friday, October 24th, 2008
Tags: google, meta, seo, WordPress
Posted in Search Engine Optimization, WordPress | | Read more

Did you find this article useful? You're welcome to post a link to this website along with the title but please don't copy the whole article. You can also link back using the following code:

<a http://www.thisismyurl.com/wordpress/fixing-duplicate-content-so-google-doesnt-see-it/" rel="bookmark" title="Fixing Duplicate Content So Google doesn’T See It.">Fixing Duplicate Content So Google doesn’T See It.</a>

About the Author

Christopher Ross About the author.
Thanks for taking the time to read my blog. If you don't already know me, my name is Christopher Ross and I'm a web evangelist living in Fredericton Canada. When I'm not writing about the Internet, I'm helping small businesses improve their search engine performance or building better WordPress web sites for clients.

Please feel free to leave a comment below, or contact me if you have any questions.

3 Comments

|
comments rss [?] | trackback uri [?]

3 Responses to “Fixing Duplicate Content So Google doesn’T See It.”

  1. Pingback: Blog Roundup for October 25th :: Christopher Ross
  2. Pingback: Free WordPress Theme - One Night in Paris :: Christopher Ross
  3. Internet Marketing Do-Follow Blog Says:
    October 26th, 2008 at 3:56 am

    Isn’t restricting crawls for tags and categories in a robots.txt file not enough? I have the first code you mention in my theme and I also have the robots file.

Leave a Reply

HBO
iTunes The Office
iTunes
LEGO - Speed Racer
BlueHost
BaseCamp
HBO
LEGO - Speed Racer
iTunes
Amazon
HBO
TrackVia
Recent Comments
  • Donace: @ Christopher I agree wholeheartedly all they need is one page; possibly some nice pictures :p I’m like...
  • Electric cars: Very nice post and I gain much more info from this post about, “How to useful my site for my...
  • Internet Marketing Strategies: That is really bad business, with the Internet making the world such a small place,...
  • Adam Love: wtf, that was prety blunt don’t you think?
  • George Matthews: well that’s effective, know of an easy way of title casing static sites, other than...
  • Market Secrets Blogger: At first this one click plugin install worked just fine but now I get the following error:...
  • Rodney@Blogging with WordPress: Nice work Christopher - not too shabby. You must have some pretty good backlinks....
  • david forex trading online: Thank you for letting it slide. I know it is annoying when people use keywords as their...
  • Ikki at SEO Blog: As Mr. forex trading online (I hate it when people don’t put their names on the Name...
  • David: One more strategy of search engine marketing is to create a buzz about your site in the internet. This can be...
Top Commentators
  • rv for sale (8)
  • Internet Marketing Strate... (7)
  • Electric cars (6)
  • Ikki at SEO Blog (4)
  • forex trading online (4)
  • RNB Love Songs (4)
  • Make Money Online (3)
  • Donace (3)
  • Mike Collins (2)
  • PizzaForADream (2)
© Copyright 2009 Christopher Ross. All rights reserved.
  • Follow my posts:
  • RSS
  • Comments
  • Email
  • Other:
  • Privacy