You may have noticed that, thanks to the magic of Gravatar, commenters on this blog now have faces besides the comments.
Gravatars on Zo'C
And as I said, it doesn’t have to be a single image for all emails. If you have different emails for different purposes, your avatar would display the image you’ve set up for it, leaving you to different images for different email addresses.
Getting Started
First things first, if you don’t know what a gravatar then the best thing to do is start by getting one for yourself, although you don’t need one in order to use avatars on your website.
Go to Gravatar’s site, sign up for free, add at least one email address and an image for it. You can leave a comment on this post and you’ll see your face besides it.
Putting Gravatars on your site — the hard way
Once you’ve put your hands on someone’s avatar, all you have to do is to get encode it using an hexadecimal MD5 hash for the email and add it to the end of this url
http://www.gravatar.com/avatar/
This is to protect the privacy of your user’s email. For instance, the MD5 hash of my email 4c7e77a76f68420298c3e2cf692a47a9. This is one directional cryptography, meaning that you can’t, in practice, know what the email is, but if you know the email, you can easily produce this string.
You can easily get my Gravatar by asking for the image at
http://www.gravatar.com/avatar/6f4484a28c0debf9a262d25b998df8f3
And you can pass parameters to for sizes and many other things. For a full list see the explanation on their site.
Putting Gravatars on your site — The easy way
Hash encoding email addresses may not be your cup of tea, but you can probably guess that there are many implementations around for Gravatars.
If you use Wordpress ≥ 2.5, all you have to do is call the get_avatar() function. The first argument is the comment author email or Hass, the second one is the size (optional) and a third optional argument is allowed to specify the URL of a default image for those who haven’t got a Gravatar yet.
<?php
if (get_bloginfo('version')>=2.5) {
echo get_avatar( $comment->comment_author_email, $size = '72');
}
?>
If you use another platform, check the extensive list of implementations that can help you integrate Gravatars on your site.






















6 Comments
Gravatars are a great addon to any blog. I have them setup on all of my blogs. It makes the reader interaction a lot better.
Just implemented this on my blog!
I used the following code to get it to work on my WP blog:
< ?php
echo get_avatar( $comment, $size = '72' );
? >
Awesome post.
http://www.michaelbubbo.com/blog
P.S. If the code I pasted doesn’t show up, feel free to delete that portion of this comment. =)
Thanks for the email tip. I used WP-Gravatar plugin to include Gravatars on my site so the coding info is a big plus.
My theme is Gravatar enabled by default, some coding knowledge is always great and warmly welcomed
i just want to know if i want to use the gravatar in my site.. is that mean that user must have an account in gravatar first … i mean i can use only the URL of the image?
I already have a Gravatar account but I don’t yet set it up. I guess I will now set it soon since I know now what is the importance of it.
Trackbacks