WP Plugin: Recent comments widget with excerpts

I wrote a WordPress plugin to modify the behavior of the recent comments widget. Since WP version 2.8.0, popular widgets have been included as core functionality. I don’t like how the recent comments widget works, so I changed it. Instead of displaying the post titles that received comments, my plugin shows comment excerpts. I made this graphic to show the difference between the default behavior and the effect of this plugin:


WordPress.org link

Visit this plugin’s page in the official WP plugin directory.


Installation Instructions

  1. Download recent-comments-widget-with-excerpts.zip
  2. Decompress the file contents
  3. Upload the recent-comments-widget-with-excerpts folder to a WordPress plugins directory (/wp-content/plugins)
  4. Activate the plugin from the Administration Dashboard
  5. Open the Widgets page under the Appearance section
  6. Drag the Recent Comments widget to the active sidebar


62 responses to “WP Plugin: Recent comments widget with excerpts”

  1. This is a better approach, I agree. Will be sure to give your plugin a shot. If it’s good (not too buggy) then we may want to mention it on our site.

  2. Thanks for your consideration, Ryan. I have been using this code for months front and center on my site http://www.fightthescams.com. I updated its WP install last night and discovered that the functionality was lost. I had modified default-widgets.php instead of creating a plugin back then. Let me know if you have any issues.

  3. hi corey,
    i like your plugin, but there’s one thing: should the ellipsis apply to all comments even if they are shorter than the length of the comment excert (50 chars is the hard-coded length).

  4. Mike:

    No, that’s not behavior that I intended. I will take a look at this issue and get back to you soon–maybe I could make the length variable, too.

  5. Tonight, I published a new version of this plugin to correct the misbehaving ellipses that Mike C described on January 6.

  6. Hi – i just started a blog and was looking for a way to showcase comments. This is such an improvement over the default — more user-focused. Any chance you might develop a way to turn on a link to the title?

    Nice work — thanks for doing it

  7. This is the plugin I want. However, if the comment is in Chinese, there are two or more ?? at the end of each comment.

  8. Hey is there a way to insert the recent comments with a php include instead of a widget? Just so i can place them anywhere in my template?

  9. It seems that in your plugin also, the comment does not link to comment page, but links to post page.

    This becomes problematic, when the defined number of comment per page would exhaust eg. if there is 20 comments per page defined, and at a point the 21st comment is posted – the links to comments in the widget would link to the post page – where the comments no longer exist!!

    There is a similar extended comment widget (by urban giraffe) that does the same kind of thing (and has the same flaw) !

  10. Anup:

    What do you suggest? Perhaps I can obtain the value of the option that determines whether or not comments are broken up into pages before creating the links.

    I don’t use comment pages, personally, so it’s never been an issue for me.

  11. Thanks for the reply. In one of my blogs there are posts with 300 / 400 comments. And I guess there are others also who may have such heavy traffic.

    In such case, one cannot put all comments on a single post page – that would cause huge loading problem – and in mobile devices they would go out of memory!

    Can’t the plugin be coded to check – whether the option of comment page is activate? If there is comment page, then it links with comment page, else it links with the post page.

  12. Hi, Thanks for your plugin.
    It’s very helpful to show commments body.
    I have something to ask you for other language user.
    Please use mb_substr instead of substr.
    In 2 byte character, substr won’t work properly.
    Thanks again.

  13. Hi Corey,

    Your plugin is fantastic. I installed it in my site, and it works very fine. How can we increase the limit of comments? Why only 15?
    Thank you very much, Dear.

  14. corey, i’m still using your plugin, but i’ve come across a few issues in the last few months that need to be addressed:

    1. the ‘comment_text’ filter should be applied to all comments before being displayed anywhere on a site. these filters can alter how a comment is displayed. (in my case i remove all email addresses using this filter, and without this filter the email address is visible for all to see … which is not good)

    2. wordpress comments allow the use of simple tags, like <a>, <b> etc. now, if the end of the excerpt is in the middle of a tag (or before it is closed), then you’ve got trouble coming because it will mess up the rest of the displayed excerpts (in lots of different ways). using the strip_tags() function will sort this out.

    with the above in mind, the one line change below will fix the proplems:

    exchange your line

    $aRecentCommentTxt = trim( substr( $aRecentComment->comment_content, 0, $excerptLen ));


    $aRecentCommentTxt = trim( substr( strip_tags(apply_filters( ‘comment_text’, $aRecentComment->comment_content )), 0, $excerptLen ));


  15. Have updated the widget but it still shows the basic 15 comments no matter how many times the number is altered and saved.

  16. Elaine:

    You’re right. I just spotted a bug that wasn’t brought to my attention yet. I’ll fix it up when I get a chance, which will likely be tomorrow or Sunday. Thanks for trying my plugin!

  17. Still a problem. Only shows five comments now, no matter how many times it’s decativated and recativated, number schanged etc.

  18. Didn’t do a backup (silly me) so can’t go back to the old plug in for the 15 comments. Hopefully, it’s just me so happy to hear suggestions.

  19. Hello!
    I had your widget for about a week and was faffing around and deleted it by mistake. I tried to install it again and it just keeps failing. Says “Could not create directory. D:/HT/thecakeempire/wp-content/plugins/latest-twitter-sidebar-widget/”

    Any ideas why I can’t reinstall?


  20. Helen:

    I think you commented on the wrong post, but that’s OK. Are you trying to install from the admin dashboard or are you FTPing the files up?

  21. Sorry Corey! I fixed it now. Did it manually through FTP rather than through the dashboard menus! Thanks for response!

  22. I got to increase the limit to 30, modifing the following lines:

    else if ( $number > 30 )
    $number = 30;

    and this one:

    I just changed the original number “15” to “30”.

    Dear Corey, thank you very much for this brilliant plugin.

  23. The line doesn´t appear, I am repeting with spaces between letter to avoid problems. (please, do not copy this line, just change the number from 15 to 30:

  24. Eduardo:

    I updated the plugin to allow up to 150 comments. You shouldn’t have to mess with the code if you have the latest version.

  25. Dear sir/madam,

    At first thanks for the plugin! It’s great. But i want the author name in bold. I think i have to change something here:

    if ( $comments ) : foreach ( (array) $comments as $comment) :
    //echo '’ . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x(‘%1$s on %2$s’, ‘widgets’), get_comment_author_link(), ‘comment_ID) ) . ‘”>’ . get_the_title($comment->comment_post_ID) . ‘‘) . ”;
    $aRecentComment = get_comment($comment->comment_ID);
    $aRecentCommentTxt = trim( mb_substr( strip_tags( apply_filters( ‘comment_text’, $aRecentComment->comment_content )), 0, $excerptLen ));
    if( strlen( $aRecentComment->comment_content ) > $excerptLen ){
    $aRecentCommentTxt .= “..”;
    echo ” . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x(‘%1$s: %2$s’, ‘widgets’), get_comment_author_link(), ‘comment_ID) ) . ‘”>’ . $aRecentCommentTxt . ‘‘) . ”;
    endforeach; endif;?>

    But i don’t know what. Could you tell me?

  26. Hi.

    Thanks for a very useful plugin! It works as intended, however what I’d like to do now is also display the nested replies to the comments. Is this possible? I figured this could be a good way for users of my site to get an overview of comments/ conversations on the site.

    Cheers for any suggestions.

  27. Martin:
    Instead of making a code change, I will look into wrapping the author names with a CSS class for the next update.

    Nested replies are not possible currently. It’s not a bad idea. I’ll see what I can do.

  28. Great plugin Corey!

    Much better than the default option.

    Would absolutely love this plugin to have options for length by “words” or “lines” in addition to characters. Looks a little funky with incomplete words. Not sure if there’s any way to auto-detect the sidebar width and character size to accomplish the “lines” option.

    Might also be nice to have an option to include the elipse (or other character) on all of the exerpts regardless of length. I was wanting to use the right arrow character “→” on all of the comments, since i have those highlighting links in post exerpts.

    Anyway, it’s good to dream and think out loud. Thanks again!

  29. Hi
    Love the plugin – just what I need. I am new at this. I have wordpress 3.3.1 and I am told that this plugin has not been tested with my version of WordPress. Is this a concern – or should I just try it ?? My theme is Waever II Pro

  30. Henriette:

    That just means that a new version of WordPress was launched more recently than when I last updated the plugin. I am using this plugin without issue on the latest WordPress on more than just this website. Go for it, and thanks for your comment.

  31. The plugin works great when I’m logged in but when i log out, it just reverts to the default. any suggestions? thank you.

  32. Hello Corey !
    Thank you for your great plugin, I would like to know if it is possible to adapt your plugin to show some extra content posted by comment form.

    I’ve extend the comment form adding a title, which is in commentmeta database.
    Here is my sql query ;)
    SELECT meta_value FROM ” . “$wpdb->commentmeta WHERE meta_key=’pmg_comment_title’ AND meta_value!=”
    How can I change your sql query to show this content ?

    I’m ready to buy a cup ;) I you help me to solve this query ! Thank’s in advance !


  33. Nice plugin. I like the functionality, however, the style was not consistent between chrome and IE. (did not test in others)

    IE did not apply correct styling to the widget.

  34. This is a great plugin for informing folks what resides inside beyond the front/home page. I made a slight modification to include colon and BReak after the commenter name. I am curious if anyone has modified to include the related Post title in addition to the comment. For example, right now I have:

    George said:
    For us it rained every day!

    Sally said:
    Cold but sunny and bright.

    Whereas those two example comments relate to two entirely different Post topics that I as admin posted. “A Trip To Spain” and “A Trip To Norway” and thus the comments listed have no context per se. But this might be useful (perhaps as an option for those who don’t want it):

    George said in A Trip To Spain:
    For us it rained every day!

    Sally said in A Trip To Norway:
    Cold but sunny and bright.

    Just a thought to add context to each comment listed. Love the plugin regardless. :)


  35. The plugin used to work great. After the latest update to WordPress something is wrong. Hoping you can help me.

    Used to show the author and what is said all on one line. Nice and neat.

    Now is a space between the author and what is said. And the next author is right under that. Very confusing!

    I’m not great with code, but there must be some way I can fix it. I have downloaded the plugin again from WordPress and re-installed it. No change.

    Thanks for your help!


    Agape,loving the way that God loves,is counterintu…

    As laypersons, God expects us to love and serve Hi…

  36. Micki:

    Mine is still working fine. You probably introduced some new CSS or removed CSS that was previously styling this widget. A WordPress core update doesn’t affect the way your theme presents content on the screen. Did you change themes, too?

  37. Hello ,
    Ya , I’am trying badly to show the title when hovering with mouse ouver the comment but no way ! Can someone help !
    However it’s a great plugin !

  38. Hi Corey.
    This plugin seems to be just what I need – but I cannot see it in WordPress’s selection of available widgets. I have followed your install instruction and can see the widget to activate it in the plugins section. I have activated it, then deactivated it, re-activated it. logged in and out and it still isn’t available to me to use. Do you know what I can do to fix this issue? Please help!

  39. Hi again Corey – I just realised that the plugin is working now!… I can’t see it in Appearance > Widgets – but it works, which is good. Thanks!

  40. Nice little plugin, i had to manually change the code however to get the excerpt to display more chars.

    An area within the widget itself were you could override this would be better, like the number of comments area already here, This would save me making sure i re-apply the excerpt length after an update of your plugin :)

  41. I haven’t been able to update to the latest version of you plugin. Each time I do (and with various templates) it breaks up the comments like this
    said This is a beautiful looking site!

    I still use an old version of the plugin that keeps it on one line.
    Any suggestions to make the update work?

Leave a Reply

Your email address will not be published.