Post Pic

WordPress hack: Canonical links for comments

Duplicate content is one of the most discussed topics in terms of SEO. Happilly, with the new rel=’canonical’ attribute, you can now reduce risks of duplicate content. Here is how to implement it for your comments pages, on your WordPress blog.

Simply paste the following code on your function.php file:

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

Thanks to I like WordPress for the useful tip!

21 Responses

Aug 05 2009 18:23

I didn’t know what rel=canonical was, so I had to look it up. Here’s a great — and witty — quickie explanation by Conversation Marketing: http://www.conversationmarketing.com/2009/02/3-reasons-to-use-rel-canonical.htm

Aug 10 2009 01:48

Hi,
I landed in your blog while searching for “Canonical tag”.
I used it in my websites but had no idea how to imlement it in WP.
Finally I got the function. Thanks a lot.

Aug 14 2009 06:22

Hi, I think All in one SEO pack plugin and Platinum SEO pack can handle it.

Aug 18 2009 04:50

haha, nice i was looking for this.

great post and keep up the good work.

Aug 21 2009 04:14

@ Rismaka : maybe that for someone who didn’t use that plugin

Aug 27 2009 11:36

Yeah, its sucks when people steel content.

Sep 13 2009 20:23

Wow. This wonderful.

Oct 01 2009 17:21

for what canoncial is ?

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required