How to include the author's photo in a WordPress post

If you have a multi-author blog, you may want to include a little author photograph with each post. The easiest way to do this is to use the Gravatar service: this is owned by Automattic, the people who brought us WordPress and Akismet. And you only need one line of code to add the picture:

<?php
echo get_avatar( get_the_author_id(), $size = '40', $default = 'PATH TO URL' );
?>

Size is the length of one side of the square image in pixels. Default is the image that will be shown if there is no Gravatar available: if you don't specify a default image, you'll get mystery man.

Add this within the loop to single.php if you want it on the single post page; or to index.php, archives.php, search.php if you want it on the front page, archives or search results (for most themes; themes may vary...).

Share this post:
  • email
  • del.icio.us
  • Facebook
  • FriendFeed
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Twitter

Posted by Sue on June 13, 2009 in WordPress.

Leave a Reply