Without a Plugin: Display Recent Comments

Without a Plugin: Display Recent Comments

This post was originally published on April 9, 2009 and is now being being republished as it has been entirely revised. The original method is removed and now replaced by a new one.

WordPress ships with a Recent Comments widget, which is very handy, but on the other hand does not give you much freedom in terms of look and feel. There are plugins out there with will offer some more functionallity, but you sometimes feel you just want to free yourself form any limitations. So here I present the recent comments function. Let’s get our hands dirty.

Here is the function that you need to put in your functions.php file.

The function has three arguments that allow you to specify the number of comments that you want to show, defaulting to 5; how long you want the comment body text to be, defaulting in 120 characters; and how big you want your gravatar to be, from 0 to 100, defaulting to 48.

Next you want to call the function from the sidebar.php of your theme or wherever else you want them to show on your site. You can do it like this:

And here I’m offering you some boilerplate CSS styles to make your recent comments look good.

I wish you find this article helpful and please make sure to subscribe as more stuff is coming in the Without a Plugin series.