Applying Author Gravatar In Post
Posted by Nile | Posted in Tutorials | Posted on 11-24-2009 | 2 Comments
Tags: gravatar
A few years ago, Gravatar (globally recognized avatar) was new and shiny, and people were implementing it into their blogs. Gravatar has since become easily integrable and users can simply put in their themes comment.php file:
<?php echo get_avatar( $comment, 32 ); ?>
Where 32 would designate the pixel size of the image that the blog owner wants to allow to be seen on their site.
However, what about those wanting to call the Gravatar to the author of a post? That can of course be done.
What yoy want to do is retrieve the blog author’s email address and get the avatar if the author has a Gravatar account. You can apply this to your index.php, single.php, archive.php where you want the author’s avatar to show on the post.
<?php
$author_email = get_the_author_email();
echo get_avatar($author_email, '32');
?>
Again, 32 is the pixel size to display the avatar. You can adjust this number to what size you wish.
You can see more documentation in the WordPress Codex about Using Gravatars. If you do not have a Gravatar account, you should really consider getting one. It is free and much better than the default mystery man that shows up in the comments if a person has no account with Gravatar.







