Post Pic

How to: Add author’s gravatar in posts

What about displaying the author picture in your posts? Sure, you can use a well known hack to display a picture located in your theme directory, but what about using Gravatar? In this recipe, I’ll show you how you can easily get the post author gravatar and display it.

To achieve this recipe, simply paste the following code on your single.php file, where you want the gravatar to be displayed:

<?php
	$author_email = get_the_author_email();
	echo get_avatar($author_email, '96');
?>

That's easy as that!

Credits goes to WpEngineer for this very nice tip!

20 Responses

Jan 17 2009 11:08

Easy :P already knew it.

Nice hack though

Jan 17 2009 15:25

Cool idea! Thanks.

Jan 17 2009 17:23

Hey Jean-Baptiste,

How about one master code combining a few things you have done. Right now I can pull in author pictures from four places: the user-photo plugin, gravatars, twitter and avatars. And lets say that’s the order I prefer them in.

So have WP check for user-photo first. If that’s not there, then try gravatar. If that’s not there try twitter, etc.

Jan 17 2009 19:44

That’s a good idea! I should write that code and post it on CatsWhoCode.com or on a blog where I do some guest-blogging :)

Jan 17 2009 20:18

Thanks man, it`s very nice ;)
I`ve made this change in my blog ;)

Jan 18 2009 03:57

Simple and nice.

Jan 18 2009 15:12

Thanks for the great tip. I have already put it to use on the site I am currently developing.

Jan 19 2009 03:03

Hey Jean-Baptiste, I’m not supposing that you took this tip from wpengineer.com, which we published some days before. ;)

http://wpengineer.com/identify-authors-gravatars/

If so, we would appreciate if you can give us the credit for it. :)

Thanks

Jan 19 2009 08:27

@Alex: You’re right, and I’m sorry to have forgotten your credit. I always credits people here on WpRecipes, but this time I have forgotten. Please accept my apologies for this! Credits and link just have been added.

Jan 19 2009 13:13

No problem at all Jean-Baptiste. That can happen, nobody is perfect. Thanks for the credit and we are glad your reader like it. :)

Jan 21 2009 08:11

Nice tip, I already used it along author description.

Jun 18 2009 05:46

Hie. The ‘96′ refers to the size of the gravatar, is it?

Jun 18 2009 10:15

@Nurlea: Yes :)

Aug 24 2009 18:24

Thanx, It’s so easy

Dec 12 2009 17:30

thanks for share!

Jan 14 2010 21:27

Very Nice…., thanks for sharing in fact i am looking for this ;)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required