How to make a wordpress theme “Gravatar Ready”

July 11th, 2008

I’ll begin with a short intro for those who don’t know what gravatar is. If you already know what gravatar is, skip to Process.

Gravatar is a small image or a picture that is used for your identification whenever you comment on others or in your blog which you have uploaded at Gravatar.com for a particular email.

Gravatars is a inbuilt feature of wordpress 2.5.1 and it works out-of-the-box. i.e without any plugins. But theme which you are using for your blog must be gravatar ready. Most of latest sports gravatars, but there are still designers who are neglecting to do add the feature. And if you are using a old theme, then you will have to work on it in order to make gravatar ready. I’ll tell you how to do it here in this tutorial. Please keep in your mind that your wordpress should be 2.5 and above otherwise you may require gravatar plugin.

Process:

1. Download the comments.php from here.
2. Replace the old file with this new one.
3. Open style.css and place the below code at the very bottom in a new line.

.commentlist li .avatar {
float: right;
border: 1px solid #eee;
padding: 2px;
background: #fff;
}

4. Save the file and upload it or you can edit it straight from the Theme Editor in your admin cp.

You can change the background and border color in the CSS according to your needs so that it matches your theme. You can get the color codes from here. And also you can set the float to left, if you want the gravatars to appear on the left side. Don’t forget to change the padding if you change the float.

Now this will display gravatars right next to comments made by you and or your visitors like this:

gravatars

What if your visitor doesn’t have a gravatar ? The gravatar spot appears like this:

no gravatar

So, if you don’t like this empty gravatars to appear in your blog, you can add Identicons in to the code. Identicons are the random images that will be generated for each unique IP and displays whenever the visitor makes comments in any blog. This is how it looks.

To add identicons, open the downloaded comments.php and find this:

<?php echo get_avatar( $comment, 32 ); ?>

And replace it with this

<?php echo get_avatar( $comment, 32, identicon); ?>

Save the file and upload or update from the theme editor. Or if you don’t like to mess with the code, you can download the one I have edited from here.

If you don’t have a gravatar, upload it from here.

This ends the tutorial and I hope it’s pretty useful. You can comment if you want to test gravatars and identicons here in this post.

This entry was posted on Friday, July 11th, 2008 at 4:23 am and is filed under Wordpress Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

14 Responses to “How to make a wordpress theme “Gravatar Ready””

  1. goobi Says:

    Awesome man! Thanks for the tutorial.

  2. Manan Says:

    Great tut. My theme has disabled gravatars to be shown and I like it that way. Goobi get yourself a Gravatar first.

  3. T Says:

    your theme customization is nice.

    gravatars.com have additional details about enabling Gravatars on various websites.

  4. Santhosh Says:

    thank u guys..

    @ manan, goobi likes identicons :p

  5. s0cKe Says:

    works?

  6. Santhosh Says:

    ^ yes, it works :) :p

  7. Kalon Says:

    Of course, it works perfectly.

  8. Aditya Says:

    Hey… Thanks. I had been wondering what was with my theme… Will try this out definately.

  9. Santhosh Says:

    Hey aditya! Hope u will add that piece of code to ur theme :)

  10. Sathya Says:

    Oh awesome. exactly what I needed. Was looking around for a decent tutorial and you’ve spoon fed it to me :P
    Thanks!

  11. Santhosh Says:

    hehe.. cheers sathya bro :)

  12. Chris Says:

    The link to the comment file is broken, any chance of a mirror?

    Thanks!

  13. Santhosh Says:

    @ Chirs, sorry for that.. the links are now fixed :)

  14. Thomas Says:

    Thanks a lot for these instructions. I found your site here through Google and just implemented this in my blog.


Leave a Reply