Monday, April 8, 2013

WordPress: Remove link from author name in Recent comments



In the Recent comments section, the author name is linked to his/her website while the actual comment title is linked to the comment page. Lot of times, site visitors click on the author name instead of comment title - thinking THAT is the comment link. They end up on the author's website instead.
So we decided to de-link (or unlink) the author name. Here's what we did:

1. We changed 2 files in the wp-includes folder: default-widgets.php and comment-template.php

2. In comment-template file, we made a copy of the function: get_comment_author_link, and pasted it as a new function: get_comment_author_name. The new function has following code:

function get_comment_author_name( $comment_ID = 0 ) {
$author = get_comment_author($comment_ID);

$return = $author;
return apply_filters('get_comment_author_link', $return);
}

3. In default-widgets file, we located the function widget() and replaced the get_comment_author_link call with get_comment_author_name as below:

foreach ( (array) $comments as $comment)
 {
$output .=  '
  • ' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_name(), '' . get_the_title($comment->comment_post_ID) . '') . '
  • ';

    }

    4. That's it. We uploaded the changed files and the author names did not have links any more.


    3 comments:

    Ersan Seer said...

    Beautiful. Works. Thanks.

    seoworking said...

    Wordpress Developer - Just simply install Hide WordPress Comment Author Link plugin and it will be automatically disable your all comment author url.

    Hema Priya said...

    This is my first visit to your blog, your post made productive reading, explaining everything in detail and it was very interesting to read. Thank you
    Wordpress developers India