How To Remove Canonical Links From Comments In WordPress Blog?

Posted by

Hi,

We can easily remove canonical/duplicate comments with the help of rel=’canonical’ attribute. You can now reduce duplicate content and for that is the way to implement it for your comments pages on your WordPress blog.

You just need to add this code in functions.php file of your theme:

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’ );

That’s it!

Thanks,

Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.