UPDATE: This hack has just recently broken. 🙁 HOWEVER, I found a nifty plugin to replace it.

With thanks to Justin P., we’ve figured out a way to make the Gravatars plugin for WordPress (available at the gravatars website) display gravatars for BOTH Comments AND Posts. Not only that, but you can specify a default image, size, rating, etc. just like the original plugin, but with different settings on posts and comments, if you like.

Here’s what you need to do –
modify your plugin gravatar.php file to the following (basically, you’re adding another function) –

function gravatar($rating = false, $size = false, $default = false, $border = false) {
global $comment;
$out = "https://www.gravatar.com/avatar.php?gravatar_id=".md5($comment->comment_author_email);
if($rating && $rating != '')
$out .= "&rating=".$rating;
if($size && $size != '')
$out .="&size=".$size;
if($default && $default != '')
$out .= "&default=".urlencode($default);
if($border && $border != '')
$out .= "&border=".$border;
echo $out;
}

function postgravatar($rating = false, $size = false, $default = false, $border = false) {
global $authordata;
$out = "https://www.gravatar.com/avatar.php?gravatar_id=".md5($authordata->user_email);
if($rating && $rating != '')
$out .= "&rating=".$rating;
if($size && $size != '')
$out .="&size=".$size;
if($default && $default != '')
$out .= "&default=".urlencode($default);
if($border && $border != '')
$out .= "&border=".$border;
echo $out;
}

Second, just like you added the img src with php gravatar embedded into comments.php inside the folder of the template you’re using, add the same code, but change php gravatar to php postgravatar, into the template page that calls your posts (probably either posts.php or index.php), and, of course, customize to your liking. 🙂

P.S. – I found that the image sizing embedded in the php code worked for comments.php only on the gravatar that was associated with the author’s email address – in case it uses the default gravatar image, I had to add a style=”width:Xpx” onto the img to force it to anything but 80×80 pixels consistently across default and assigned images. I don’t know if this sizing issue is present on posts as well.