How To Remove The URL From The Commenter’s Name In WordPress

This isn’t an article about ordinary comment removal – it’s the URL in the comment’s name, not in the comment itself.

The problem is simple: A person leaves a comment, and includes their URL. In the comment display, the name is a live link.

One day I decided I wanted to clean that up, and prevent links. No live links, just comments. That way, comments are just comments, no SEO (search engine optimization) benefit, and less spam.

You might argue that preventing links in commenter’s names is naughty, and against the spirit of the Internet, or bad karma/mojo. I acknowledge your feelings, and so I recommend you DO NOT do it on your site. However, when I comment elsewhere, I regularly see my URL removed, so I don’t think it’s such a big deal. And don’t forget, the URL has not been useful for linking for a long, long time – it merely gives the comment reader a place to go if he/she wishes to click, which I think happens very, very rarely.

Many solutions recommend hiding the URL entry in the comment form – but that does nothing for comments already in the system, unless you want to do some fancy SQL-FU on them. I didn’t, so it took awhile to research another solution, one that was low impact: I just removed the HTML from the commenter’s name before displaying.

The end result is rather straightforward – WordPress has a hook called get_comment_author_link which can be passed another function to remove the URL (HTML) code for the name field. Easy Peasy – just add this to your theme’s functions.php file code:

function utopia_authorCommentFilter( $link ) 
{
  global $comment;
  return strip_tags( $link );
}
add_filter('get_comment_author_link', 'utopia_authorCommentFilter');

functions.php is loaded with every page, so any page that displays the comments will add this hook, and remove the URL from all author names in comments. Ta-Da!

Comments are closed.