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
- Download recent-comments-widget-with-excerpts.zip
- Decompress the file contents
- Upload the recent-comments-widget-with-excerpts folder to a WordPress plugins directory (/wp-content/plugins)
- Activate the plugin from the Administration Dashboard
- Open the Widgets page under the Appearance section
- Drag the Recent Comments widget to the active sidebar
Enjoy!
Comments
62 responses to “WP Plugin: Recent comments widget with excerpts”
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.
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.
[…] has written a new WP plugin that modifies the behavior of the recent comments widget. Instead of displaying the post titles that received comments, this plugin shows comment excerpts. […]
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).
regards
michael
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.
Tonight, I published a new version of this plugin to correct the misbehaving ellipses that Mike C described on January 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
Joanne:
I am not sure what you mean by “a link to the title”
Hi Corey ~ Hey, is there any way I can exclude my replies to comments so that they will not show in the “most recent comments”? Thanks! Christine
Christine:
There’s no option for that right now. I may be able to include that with the next version.
This is the plugin I want. However, if the comment is in Chinese, there are two or more ?? at the end of each comment.
caii:
Can you show me an example or give me some Chinese content that I can use to create a test case?
Thanks
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?
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) !
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.
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.
My widgets looks like this:
http://since83.com/demos/83images/images/26365806411899634464.jpg
Any help to make it look nicer is welcome. pls mail me
Thanks for the widget! Tweaked ours to put break after author, and quotes around the comment: http://ghkim.com/blog
Cool! It is always nice to see how people are using my plugins. Thanks for the link.
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.
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.
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 ));
with
$aRecentCommentTxt = trim( substr( strip_tags(apply_filters( ‘comment_text’, $aRecentComment->comment_content )), 0, $excerptLen ));
okso
mikeC
Have updated the widget but it still shows the basic 15 comments no matter how many times the number is altered and saved.
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!
OOOh, I spotted something before anyone else? That’s a first for me! :)
I pushed an update to fix the bug you found, Elaine. Thanks for using my plugin and helping everyone else.
Still a problem. Only shows five comments now, no matter how many times it’s decativated and recativated, number schanged etc.
15 was better than 5!
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.
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?
Thanks!
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?
Thank you for fixing the widget. It is brilliant! Works very well and looks great!
Sorry Corey! I fixed it now. Did it manually through FTP rather than through the dashboard menus! Thanks for response!
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.
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:
I can´t get…
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.
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:
<?php
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?
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.
Martin:
Instead of making a code change, I will look into wrapping the author names with a CSS class for the next update.
Pete:
Nested replies are not possible currently. It’s not a bad idea. I’ll see what I can do.
Thanks for the reply Corey. I look forward to future developments!
Hi, thanks for this excellent plugin. I am from Chile and want to know how can I show longer comment excerpts :)
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!
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
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.
The plugin works great when I’m logged in but when i log out, it just reverts to the default. any suggestions? thank you.
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 !
Isabelle
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.
YoYo-Pete: Are you using the latest versions? That’s Chrome 17 and IE 9, today.
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. :)
Bob
Hi Corey,
What a great plugin! Is it possible to add the php directly in the template file?
Thanks
I’d love to be able to exclude myself (i.e. my replies to reader’s comments) from this display. Is that possible?
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!
code:
JerryCarlisle
said
Agape,loving the way that God loves,is counterintu…
JerryCarlisle
said
As laypersons, God expects us to love and serve Hi…
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?
Comment refused to display the title of the post
Thanks for the plugin, i figure it out. It is working fine
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 !
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!
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!
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 :)
Thanks for this plugin. This is what I’m looking for
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
Glenn
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?
Thanks!