WordPress hack: Canonical links for comments

by Jean-Baptiste Jung on August 3, 2009

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!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

WordPress hack: Canonical links for comments