How to remove author name from recent comments widget in WordPress

I recently started to use widgets in all my WordPress blogs. It’s really easy to add new features via widgets but some times you may need some changes to be done which are not available in WordPress widgets.

For example: I decided to show recent comments in my WordPress blog via widgets but before using the widgets, I used to show the recent comments as URLs to the comments. But via WordPress widget, the recent comment was shown something like this:

“Author Name” on “URL to the Comment”

Where I like to only have this:

“URL to the Comment”

I thought it will be easy to change this but I was wrong. There is no option available in WordPress widgets that can change this. So I tried to find some other solution.

In order to show only the URL to the recent comments in WordPress using widgets, you will have to edit a WordPress file.

The file name is: “widgets.php”

I am changing this article as this solution is no longer valid for the latest WordPress release.

Now instead of “widgets.php”, download/edit this file:

“default-widgets.php”

And it can be found here

\wp-includes

You need to search for this function in the “widgets.php” “default-widgets.php” file

function wp_widget_recent_comments($args) { function widget( $args, $instance ) {

Below this function, look the line that starts with this code:

echo ‘<li class=”recentcomments”>’ . sprintf(__(‘%1$s on %2$s’)

echo  '<li class="recentcomments">' . /* translators

Now you have to change this

(‘%1$s on %2$s’)

To this:

(‘%2$s’)

Save the file “widgets.php“default-widgets.php” and upload it to your server. From now on, only the URL to the recent comment will be shown.

11 Comments so far
  1. Administrator

    November 12, 2008 9:41 am

    I tried to find the code you mentioned, which is,

    “$widget_title = sprintf( _c(’%1$s: %2$s|1: widget name, 2: widget title’ ), $sidebar_args['widget_name'], $widget_title );”

    In the widgets.php, I was failed to find it [2.6.3].

    Anyway, open the widgets.php file which is in wp-includes and look for this code

    ->comment_post_ID) . ' < / a > ' ) . ' < / li > ' ;

    You need to add “< /*br > ” in the last part which is

    “'< / a > ') . '< /li > ';

    So the code which will give you one line break will be like this:

    ->comment_post_ID) . '< / a > ') . '< / li > < / br > ';

    NOTE: Remove all “*” “Asterisk”

    If you want more space, then add more line breaks


  2. Shafi

    November 12, 2008 9:14 am

    I am using WordPress 2.6.3.
    How do I get a line-break like a between comments in the Recent Comments widget.
    I have this statement in widget.php file:

    $widget_title = sprintf( _c(‘%1$s: %2$s|1: widget name, 2: widget title’ ), $sidebar_args['widget_name'], $widget_title );

    Thanks
    Shafi


  3. Truncal

    February 6, 2009 9:05 pm

    Thanks for the post. I was wondering where to find that file. Q. would you know how to modify it to add a class to the name? I would like to control the styles a bit better.


  4. Justin

    June 14, 2009 2:58 am

    Thanks for the post. This has helped me to get much closer to what I’m looking to do: I want in my Recent Comments widget to display Commentator’s Name: Comment – but if “%1$s” is the commenter, do you know how can I find what string = comment?


  5. Bill

    June 26, 2009 7:54 pm

    Now that 2.8 is out, the new name of the file is “default-widgets.php”.


  6. osman

    July 2, 2009 11:49 pm

    thx bill. for 2.8 info. luv ya


  7. haydi bastir fener

    July 3, 2009 1:00 am

    how can i comment_content to the recent comments list?


  8. sonia

    September 19, 2009 4:21 am

    thanks for telling me how to remove the author name from the recent comments. excellent :)


  9. Dyce

    January 7, 2010 10:42 am

    I also wanted to display the actual comment instead of the link. did anyone figure this out?


  10. Administrator

    January 8, 2010 12:19 am

    For people who want to show comment content:

    The Echo command which I have mentioned in the post: go there and you will find functions like:

    get_comment_author_link() etc

    There is also a function:

    get_comment()

    I am pretty much sure that this is the function that fetches comment body from DB.

    I currently am not using this widget in my site: so I have not tried it.

    You just need to try few different coding changes in the Echo command mentioned above and I am sure that you will be able to pull the content body instead of comment URL.


  11. ot

    March 17, 2010 11:33 pm

    Thanks admin :)


Leave a Comment

Name (required)

Email (required)

Website

Comments