Paulund
2012-07-03 #wordpress

Add rel="nofollow" To WordPress Comment Reply Links

When using Wordpress comments you can easily reply to a comment directly on the page by clicking on a reply link which will be positioned next to the comment.

To add the comment reply link to the comment you need to use the Wordpress function comment_reply_link(). If the Javascript file comment-reply.js is loaded on the page then the comment form will be moved just below the comment. The arguments for the comment_reply_link function are: - $args - Array of options for the comment reply link

  • $comment - The comment ID to be replied
  • $post - Post ID to the comment is displayed on.

Arguments Array

  • add_below - To the comment for the comment form to be moved under
  • respond_id - ID for the respond sent to the javascript move comment form function.
  • reply_text - The text to use in the reply link
  • login_text - Text to display if the user needs to be logged in to reply to comment.
  • depth - Depth of the reply
  • before - HTML to add before the comment reply
  • after - HTML to add after the comment reply

As you can see from the above options there are lots of things you can do to customise the reply link that is displayed in the comments section. But there is an SEO problem is this reply link. ## SEO Problem With Reply Link

This reply link will include the comment ID in the URL and will send you back to the page with the comment form in place to make your reply to the comment. The problem is that search engines can follow this link on your page and will index the page the links goes to. This page is the same as the current page but will have additional query string options to take to back to the comment form. These URLs are then indexed in the search engines creating duplicate context in the search engine index. A good way to solve this problem is to add a rel="nofollow" to all your comment reply links, which tells search engines not to follow this link. Below is a Wordpress snippet to add to your functions.php file to add a rel="nofollow" attribute to your comment reply links.

/**
* Add a rel="nofollow" to the comment reply links
*/
function add_nofollow_to_reply_link( $link ) {
    return str_replace( '")\'>', '")\' rel=\'nofollow\'>', $link );
}

add_filter( 'comment_reply_link', 'add_nofollow_to_reply_link' );