Canonical Links for Paginated Comments (8 posts)

  1. trivum
    Posted 1 year ago #

    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='http://mysite.com/uncategorized/my-post/' />

    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='http://mysite.com/uncategorized/my-post/comment-page-2/#comments' />

    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?


  2. danielsemper
    Posted 1 year ago #

    I have the exact same problem. I am also looking for a solution without plugins, have you found anything?

  3. trivum
    Posted 1 year ago #

    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.


  4. danielsemper
    Posted 1 year ago #

    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.

  5. trivum
    Posted 1 year ago #

    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.

  6. danielsemper
    Posted 1 year ago #

    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":


    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 :)

  7. trivum
    Posted 1 year ago #

    Thanks for the tip.

  8. Rogerio Martins
    Posted 10 months ago #

    does not working stalium

Topic Closed

This topic has been closed to new replies.

About this Topic