WordPress.org

Ready to get started?Download WordPress

Forums

Canonical Links for Paginated Comments (7 posts)

  1. trivum
    Member
    Posted 6 months 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";
    endif;
    }
    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?

    Thanks.

  2. danielsemper
    Member
    Posted 5 months ago #

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

  3. trivum
    Member
    Posted 5 months 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.

    http://wordpress.org/plugins/all-in-one-seo-pack/

  4. danielsemper
    Member
    Posted 5 months 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
    Member
    Posted 5 months 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
    Member
    Posted 5 months 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":

    http://stallion-theme.co.uk/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:

    From:
    Index All Paged Comments
    To:
    Index Main Post/Page Only : Block Paged Comments 2,3,4...

    -----
    Exactly dealing with the problem :)

  7. trivum
    Member
    Posted 5 months ago #

    Thanks for the tip.

Reply

You must log in to post.

About this Topic