Gravatars

Filed Under: Blogging, WordPress

GravatarAmong the great new features introduced in WordPress 2.5 is the built-in support for Gravatars, or Globally Recognized Avatars. Global because once you sign up for a free account your email address is associated with the image you chose and will be automatically displayed on any web page that supports the feature. To enable this feature in WP 2.5 click on Settings > Discussion then scroll down to Avatars. The rest is self-explanatory I think.

Of course this being something new to WordPress 2.5 your theme may or may not support the function. If you’re using an older theme then it probably doesn’t. But don’t fret because it’s easy to implement without the use of plugins.

The function that displays Gravatars is get_avatar() and there are a number of parameters that can be used with it. Here is an example from the Codex,

<?php echo get_avatar( $id_or_email, $size = '96', $default = '<path_to_url>' ); ?>

The parameters used above are:

  • id_or_email (required): Author’s User ID (an integer or string), an E-mail Address (a string) or the comment object from the comment loop
  • size (optional): Avatar display size (max is 512)
  • default (optional): Absolute location of the default avatar to use (used when the person has no email address associated with them)

In my case I chose to use the email address option. Using this theme’s comments.php as an example, I placed the call alongside the comment author’s name and assigned it its own span class. This is what it looks like,

<div class="author_meta">
<p class="author_meta"><span class="user"><?php comment_author_link() ?></span><span class="comment_edit"><?php edit_comment_link('Edit','(',')'); ?></span><span class="gravatar"><?php echo get_avatar( get_comment_author_email(), '50' ) ?></span></p>
</div>

Then I styled it in style.css as such,

.author_meta span.gravatar {float:right;border:2px double #bbb;display:block;margin:-20px 10px 5px 0;}

That’s it. Of course you will probably have to experiment with the placement of the function in your own theme and its styling but it’s really not that hard. It took me all of 10 minutes to get it up and running. If you’re not comfortable with doing this manually there are a number of plugins you can choose from including the official Gravatar.com Plugin.

Further reading:
http://codex.wordpress.org/Using_Gravatars

 

Thanks for visiting! If this is your first time here why not grab the RSS feed. You can also follow this discussion by checking the "Notify me of followup comments via e-mail" box or by subscribing to the comments RSS feed. Please scroll down to leave your comment.

2 Comments so far. Add Yours Now!

  1. Ismail

    Len, I came accross with Pavatar, similarly to Gravatar. Check that out.

  2. I use Gravatar only because it is owned by WordPress but I’ll check out Pavatar. Thanks for the tip.

Reply to “Gravatars”

Please note: Comment moderation is in effect. It may take some time for your comment to appear. There is no need to resubmit it.

Management does not necessarily endorse or agree with comments left here. Management reserves the right to not publish comments it deems unfit. Play nice.

 

Subscribe

Click below to subscribe.

  • Subscribe to the feed!

Catch it Live!

Live weekly show featuring the movers and shakers of WordPress.

  • WordPress

Just Say No!

To themes using obfuscated code.

  • Say No to Obfuscated Code!

Powered By ...

Is there anything else? Anil?

  • Powered by WordPress!