Dealing With Duplicate Content Issues on WordPress Comments Pages

by Steve on April 18, 2009

I saw a tweet today about WordPress comment page duplication issues related to SEO. While the word is still out as to just how much damage it does or doesn’t do to your ability to get found by the Great G, this specific problem is relatively easily fixed — and not by disabling the paged comments feature that the Wizards of WordPress have so kindly coded for us (you ever had a post with 300 comments? you’ll understand what I mean…).

All it takes is a little bit of code in the functions.php file in your theme. If you’re uncomfortable editing your theme files or don’t know how, leave a comment and I’ll whip up a little plugin. This may be a good time to learn to edit your files, though :)

This little bit of code doesn’t affect anything but WordPress comment pages. If you use WordPress for something other than a plain-vanilla blog, you may need the horsepower of Yoast’s Canonical URLs plugin for WordPress.

So in your functions.php file, insert the following code (I split the echo lines up for clarity, normally they’d be all on one line):

function canonical_for_comments() {
 global $cpage, $post;
 if ( $cpage > 1 ) :
  echo "\n";
  echo "<link rel='canonical' href='";
  echo get_permalink( $post->ID );
  echo "' />\n";
add_action( 'wp_head', 'canonical_for_comments' );

Make sure you paste the code before the last ?> characters at the end of the file.

For those of you who care, here’s a quick explanation of what the above code does — you’ll get a short intro into the behind-the-scenes functioning of WordPress.

When a visitor navigates beyond the first page of comments, the variable $cpage contains the page # that’s being displayed. The $post variable contains all of the information about the post. The function tests to see if we’re on a comments page greater than 1, if so, it spits out the <link rel=…./> characters. But where does it spit them?

That’s controlled by the add_action line. We’re telling WordPress that when it’s building the head section (‘wp-head’), to add our special ‘canonical_for_comments’ function.

Simple, easy schmeezy.

{ 7 trackbacks }

Canonical URL’s, Optimized Permalinks | Cordobo
April 26, 2009 at 3:07 pm
Comment page in Wordpress 2.7 and SEO. |
April 28, 2009 at 10:45 pm
Canonical URL’s, Optimized Permalinks | Word Press Magazine
July 19, 2009 at 12:12 am
WordPress hack: Canonical links for comments
August 3, 2009 at 12:02 am
WordPress hack: Canonical links dos comentários | Ajuda Wordpress em Português
August 4, 2009 at 10:32 am
WordPress hack: Canonical links for comments « Test Blog
August 31, 2009 at 7:22 am
rel canonical Google sagen was die richtige Seite ist
April 30, 2010 at 2:49 pm

{ 12 comments… read them below or add one }

Harsh Agrawal April 19, 2009 at 2:51 am

Thanks man , I have a post with 900 comments and I was facing bis issue regarding comment dupication


Steve April 19, 2009 at 2:55 am

You’re welcome. Thanks for commenting!


Chetan April 28, 2009 at 10:33 pm

The use of canonical meta tag is really good instead of using the trick that i have given in my blog. You have given amazing illustration for the WordPress people to save the Google penalty bcoz of duplicate content.
But still i think this is not for the new users, who don’t want to edit the PHP pages.
But still its really helpful and easy to implement. :) G8 work


Introspective July 13, 2009 at 7:43 am

I used to publish my articles, but now I wander should I stop doing this, because the risk of duplicate content penalty. Should I stop publish my articles on article directories?


Steve July 13, 2009 at 12:30 pm

NO! Don’t stop! You may want to reword them some, or run them through a GOOD spinner (I don’t generally like article spinners; I haven’t found one yet that works well). The duplicate content penalty is a myth. There is no penalty.

The danger with duplicate content is that an article on a directory may rank higher than the article on your main site. This happens often because of the weight that Google gives some of the bigger article directories.


Bilal Ahmad November 10, 2009 at 8:22 am

Ohh Thank you friend.


Goginoo January 9, 2010 at 8:19 am

Thank you very much, this was very useful for me :)


Infographiste January 30, 2010 at 11:13 am

Hey steve thanks for this useful tuto and easy to follow, have a great week end


shoaib hussain February 10, 2010 at 4:29 am

this is something that i have been wondering bout-what exactly canonical is……..thnx a lot


Kenneth May 21, 2010 at 1:13 am

Hi, thank you for posting this information, I appreciate
your work.

Best Regards,



Jyri Väätäinen July 22, 2010 at 9:46 am

Best tip… i search plugin for this… but your site tip do it very simple.


Massage Holster December 4, 2010 at 12:03 pm

I haven;t had a problem with this but its good to know. I appreciate how easy your instructions are to follow.


You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>