Support » Fixing WordPress » Canonical Links for Paginated Comments

  • It seems that when you paginate comments, the additional pages don’t have their canonical links point back to the original page. This would seem to lead to duplicate content issues (i.e. same post, just different comments on p.2, p.3, etc.).

    For example, on the first page of the post, the canonical link looks like this:

    <link rel=’canonical’ href=’’ />

    When I paginate the comments, however, I now have multiple pages. I would like all of those pages to point back to the original page. Instead, they look like this:

    <link rel=’canonical’ href=’’ />

    I did find some code I thought might do the trick, but it didn’t. (Maybe it’s old.)

    Here’s the code I found:

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

    Any ideas for how to change this so that all the canonical URLs point back to the original?


Viewing 7 replies - 1 through 7 (of 7 total)
  • I have the exact same problem. I am also looking for a solution without plugins, have you found anything?

    I know you’re looking for a solution without a plugin, but I did find that the All In One SEO plugin did the trick.

    I guess I will have to try it. But it is a plugin with 20+ features when we just need one. Like killing a mosquito with a gun.

    And it is strange that by default WordPress commits this mistake.

    I believe the mistake is “built in” because if you were to paginate a post, you wouldn’t want a canonical link pointing back to the first page (as all the pages would hold different content).

    It seems there’s no differentiation between paginated comments and paginated posts.

    I downloaded the canonical.php and tried to edit and correct this issue directly in its code, but it is full of several functions and conditions, not an easy task and not a good solution for future updates of the source code.

    Finally the best and easiest solution that I could find was to install the “Stallion WordPress SEO Plugin”:

    Stallion WordPress SEO

    It mainly deals with canonical options, and after the installation you only have to go to its configuration and change the last option that says:

    Paged Comments on Posts and Pages:

    Index All Paged Comments
    Index Main Post/Page Only : Block Paged Comments 2,3,4…

    Exactly dealing with the problem 🙂

    Thanks for the tip.

    does not working stalium

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Canonical Links for Paginated Comments’ is closed to new replies.