Remove Link or Unlink Comment Author Name in WordPress

I am still working on that WordPress plugin that heavily modifies the comment template and adds lots of extra functionality a WordPress blog should have. On doing that, I wanted to have the link removed from comment author name even if the Website field is filled with the commentator’s URL. All the *fixes* I came across were by manually editing the comment-template file within the WordPress core files.

That is, in fact, a very very bad idea. You never should touch the WordPress core files. You will not only loose the customization on an upgrade, but may also expose some security loophole. You may completely disable the Website filed from WordPress Admin, but that’s not a solution in my case.

The only recommend way to unlink or remove link from comment author’s name is by using or to be precise, adding a filter at the get_comment_author_link hook which is called to link the author’s name if there’s a valid URI entered in the URL field. The hook is there at the line number 147 (As on WordPress 3.5) in wp-inclides/comment-template.php file.


It accepts the filter on $return variable and we can easily modify that to suit our needs. Here is an example of a code that checks if the comment type is a comment (not a trackback or pingback) and an URL is attached to it then it removes the URL and returns the Name. The original URL entered while making the comment remains untouched in case you want to use it later.

function unlink_comment_author($return) {
	global $comment;	
		$author = get_comment_author();
	if ((get_comment_type() == 'comment')) {
		if ($comment->user_id > 0 && $user = get_userdata($comment->user_id))
			return $return;
			return $author;
	} else {
		return $return;

add_filter('get_comment_author_link', 'unlink_comment_author');

You can add that piece of code in your theme’s function.php file to activate the feature. You can also create a plugin with that code if you don’t want to touch your theme files.

Get Updates In Your Inbox

Get the WordPress Tips and latst Internet Marketing ideas delivered directly to your email inbox, plus access to our FREE Pro Blogging Model blogging guide.

You need to confirm your email once. Don't worry, we hate SPAMs as much as you do


Speak Your Mind

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

You may use these HTML Tags and Attributes

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>