DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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";
add_action( 'wp_head', 'canonical_for_comments' );

Thanks to I like WordPress for the useful tip!


  1. Thanks for the code, duplicate content has been my headache for months. I hope this would solve the problem.

  2. i need to put it on wp includes > function.php ? is it right ?

  3. thank you for the code, it will definitely helpfull for me, takes a while to figured out on the implementation, as I don’t have any skill on coding

Leave a Comment

Your email address will not be published. Required fields are marked *