Quick Online Tips
Home     About     Popular     Photoblog     Themes     Advertise     Shop     Jobs     Contact

How to Add Gravatars to WordPress Themes

July 31st, 2008
ADVERTISEMENTS

Add Gravatars to your WordPress theme. Gravatars are a quick way to add a personal touch to your blog comments by displaying the avatar of the commenter alongside their comment. The latest Wordpress versions incorporate Gravatar support by default (you don’t need a plugin anymore!). This article will show you how to add gravatars / avatars to your wordpress theme in a few minutes.

Show Avatars in Wordpress

First you need to enable your wordpress theme to display avatars. Afer logging into Wordpress admin, go to Settings > Discussion and for the Avatars.

Add Gravatars to Wordpress Theme

Then you will have to set the php code in your comments.php in the appropriate area where you want the avatars to appear (usually after the individual comments li tags). Add this code there.

<?php if(function_exists('get_avatar')) { echo get_avatar($comment, '40'); } ?>

If gravatars are enabled from your Wordpress Admin settings, then this code will show avatars or will disappear. The “40″ signifies a avatar size of 40px by 40px square, you can edit this to suit the size of your theme template.

How to style the Gravatar?

You basically need to style the .avatar class displayed by the php code. Try some css examples below and edit it to blend with your blog design.

#comments .avatar {
float: left;
margin: 0;
padding: 0 4px 0 0;
}

or the position can be fixed to the top-left of the individual comments.

#comments .avatar {
position: absolute;
top: 1px;
left :1px;
}

You can also use img .avatar to style the tags. Using different CSS styles, you can position or align avatars wherever you like.

Optimizing Blank Avatars

Not all your commenters would have signed up for Gravatars. So what do you do with the blank avatar spaces? Showing the default mystery man or gravatar logo is not a good idea.

Instead you can opt to display Identicons, Wavatars and MonsterID to get some automated visually appealing avatars. This will automatically generate some cool avatars for all your comments. I personally like the Wavatar.

Hide NSFW / Adult Avatars

Gravatars are rated and you can opt to show family safe gravatars on your site only from the Avatar settings

Well that’s it. Your blog theme is now gravatar enabled.

Get a Gravatar - If you don’t have a gravatar already, Sign up for it today. With so many blogs supporting gravatars, it will give your comment better visibility. Get the new version of QuickPress theme, now supporting Gravatars.

RSS Subscribe RSS feed     Bookmark and Share



15 Responses to “How to Add Gravatars to WordPress Themes”

Leave a Reply

  • Subscribe free daily email newsletter Why?
  • RSS   Feed readers   Add to Google Reader or Homepage   Twitter
writeWrite a guest article - Showcase your site to our active community of bloggers, technology experts, and geeks. Now read 100+ guest articles
Jobs
Jobs on SEO | Blogging | SEM | Marketing | Software | More...
Jobs in Google | Yahoo | Microsoft | Adobe | Ebay | Cisco | Intel
Post a job - only $50 for 30 days! | 8 more reasons

Must Buy Software