How to Remove Duplicate Pages in Tree Comments

Tree Comments

Search engines don’t like duplicate content. WordPress adds many pages that are repeated. You need to get rid of them so that the site is well-indexed and receives traffic. Duplicate discussions are no exception. These are the Replytocom pages that appear with a Reply button when tree comments are enabled. Let’s figure out how to remove them.

Replytocom – what is it?

This feature works when the site administrator enables nested comments. Reply button appears with a link

https://site.com/hello/?replytocom=12345#respond

In address 12345, this is the unique identifier (ID) of each comment. The number of such links will be equal to the number of published comments. For these repeated pages, Google and Yandex can lower your blog in the search results.

How to remove duplicate pages in discussions

There are several ways. Choose the one that is convenient for you.

In the WordPress admin

Everything is simple. You need to disable nested comments.

  1. Open the admin menu Settings > Discussion.
  2. Uncheck the box next to Allow tree-like (nested) comments x levels deep.
  3. Click Save Changes .

Yoast SEO

If you use this SEO solution, then this option is already built into it. Upon activation, Yoast will automatically remove Replytocom links.

Also see: The Best Q&A Plugins in WordPress

ClearfyPro

Clearfy Pro is a multifunctional premium WP site optimization plugin that will easily remove duplicates on comment pages. For this:

  1. In the admin panel go to Clearfy Pro.
  2. On the Duplicates tab, enable Delete? replytocom.
  3. Click Save Changes.

htaccess

In this case, if you follow the duplicate link, a 301 redirect to the main one will work. To do this, at the end of the file, insert

RewriteCond %{QUERY_STRING} replytocom=
RewriteRule ^(.*)$ /$1? [R=301,L]

robots.txt

It is needed for search robots to “tell” them which pages of the resource should be indexed and which should be hidden. To prevent duplicate pages of Replytocom comments from getting into the index, add one line

Disallow: /*?replytocom

functions.php

This code does not remove duplicates, but only adds the canonical attribute to the link of the Reply button.

add_action( 'wp_head', function() {
global $cpage, $post;
if ( $cpage > 1 ) {
echo "\n";
echo "<link rel='canonical' href='";
echo get_permalink( $post->ID );
echo "' />\n";
}
});

Leave a comment

Your email address will not be published. Required fields are marked *