How To Add Gravatars For The Post Author in WordPress

Now that Gravatar support is part of the WordPress core adding them into your WordPress theme is easy. Adding them to your comments has been documented. How about adding them to your post titles to highlight the comment author? Within the loop? That’s fairly easy too. Here’s the code:

<?php echo get_avatar( get_the_author_email(), '80' ); ?>

Pretty simple, huh? get_the_author_email outputs the post author’s email and the “80″ is the size of the avatar image in pixels (you can change that). How this will look depends on how you use it; where you put it in the theme (it has to be in the loop!) and how you style it.

Want an example? I had to figure this out for an upcoming project so…

Author Gravatar Example

Look at that frighteningly intense young man there in black and white. Good grief, it’s me! The author of the post! The code, it works! It works!

Ahem. Excuse me. I get a little excited about these things. Good luck using it in your own theme!

By the way, did you know WordPress has built in email protection from spam bots (read Disguising Your Email)? I didn’t. Neat.

162 thoughts on “How To Add Gravatars For The Post Author in WordPress

  1. Pingback: Wordpress Hacks « reeboot strategy

  2. Pingback: The Ultimate Guide To Wordpress Hacks And Customizations | Web design news and tutorials

  3. Pingback: Wordpress Hacks And Customizations « moemir

  4. Pingback: | Technoweblog

  5. Pingback: Wordpress Hacks e Customizations! | sinergie.::.websolution | il blog

  6. Pingback: 40+ Most Wanted Wordpress Tricks and Hacks « Tips for online tech users, Designers, Blogger, Learners…

  7. Pingback: 40+ Most Wanted Wordpress Tricks and Hacks | Tut7

  8. Hi Ian,

    I am new to Gravatars. I want to add Gravatars to my blog so that at the bottom of each blog post, the post author’s Gravatar will be displayed along with their description and website. Is there a widget for that? Here is an example of what I am looking for:

    http://www.detroitmommies.com/2010/06/rhpl-evening-family-storytime/

    If you look at this post, at the bottom you will see the Autors Gravatar, a description of the author and a link to their website. Is there a plug-in or a widget that does this? I have the same theme blog which is the lifestyle theme.

    Thanks,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s