Add Gravatar Support To WordPress Theme

This small tutorial will tell you exactly how to add Gravatar support to your WordPress theme. Gravatars are used to spice up up your comments with a small “globally recognized avatar” the commentator chooses to use with an email address.

A Gravatar (like used above) is coupled to an email address you registered at gravatars.com. If you want to install Gravatars to your theme registering a email address is the first thing you should do.

Install Gravatars To Your Theme

Fortunately Gravatars have been included in the WordPress core codes just yet, so we don’t need any additional plugins to make everything run smoothly.

  • First you have to make sure Gravatars are activated. Navigate to Settings > Discussion in the WP-admin section of your blog. Scroll down to Avatars and choose the settings you like.
  • Open up comments.php
  • Find:
<ol class="commentlist">
  • The codes below are ‘how your comment will be shown when listed’. You can place your Gravatar where you want. I suggest you choose a spot close to the commentators name.
  • Codes:
<img src="<?php gravatar(); ?>" alt="Gravatar" />
<?php gravatar("rating", "size", "default", "border"); ?>
  • Rating – Rate which Gravatars to show:
    • G — Suitable for all audiences
    • PG — Possibly offensive, usually for audiences 13 and above
    • R — Intended for adult audiences above 17
    • X — Even more mature than above
  • Size – Default size of your Gravatar is 80×80px. Change that to anything you like.
  • Default - The default avatar when the email address isn’t registered at Gravatar.com. Use an URL here.
  • Border – If you want to have a border around your Gravatar, change this. Add a HEX color code to change the color of your border.

Use Right Away

A fully functional Gravatar function you can use right away is below:

<img src="<?php gravatar("R", "32", "", CCCCCC); ?>" alt="Gravatar" />
Liked this post? Subscribe, or Share and Enjoy:
  • Digg
  • del.icio.us
  • Blogosphere News
  • Design Float
  • DZone
  • StumbleUpon

Tags

This article is written by:

Name: Stefan Vervoort

URL: http://www.divitodesign.com

Description: I am a 18-year-old webdesigner and blogger from Waalwijk, the Netherlands. I also blog at WPTOY and work at DivitoMedia.

9 Responses

  1. seonext says:

    Well, I always enjoy seeing these cute little avatars!
    Now using them will surely be more enjoyable.
    Thanks for this information :)

  2. @SEONEXT – Me too. :) Why haven’t you linked an Gravatar to your email address yet?

  3. [...] improve the user experience of the comment section of your blog you can do a couple things. You can add Gravatar support to make the comments more appealing, but there is [...]

  4. Mature says:

    Thanks! Good work.

  5. thanks for this info…

  6. Nice. I’ve always loved the avatars. So cute and nice. Thanks for the useful information. I always wanted to try it out. I ran through your blog and your posts are really informative. Keep up the good work. Cheers

  7. Thanks for the tutorial on setting up a gravatar. I guess the next things I need to do are go out and get the plugin, register my email, and then find a image to use…Hmmm…need to figure out if I should use a photo, or some cool image related to my site!- Matt

  8. keith Rich says:

    I like it and my kid as well!

  9. Thanks! Can’t wait to add this to the blog I’m building! Now the hard part will be deciding what picture to use for me!