@pajohns,
There is some info missing here, like if you are using a premium theme that is involved here, etc. You can learn more about the default gravatar behavior here:
https://codex.wordpress.org/Function_Reference/get_avatar
If you are talking about raw code on a custom theme, try (i.e.):
<div class="gravatar" style="background-image:url(https://www.gravatar.com/avatar/<?php
$authoremail = get_the_author_meta('user_email');
echo md5(strtolower(trim($authoremail)));
?>?s=96)"></div><!-- end gravatar -->
Better to use it as a CSS element background and not a true image in my opinion, then you will retain more control over style, and then the gravatars will not be scraped by social media sites for sharing, etc.
Keep in mind the difference between CSS height, HTML height, and then the actual image’s height (called by the ?s=XX query in the gravatar’s URL).
Hi Jejani,
I’m not using a premium theme – made it myself, so pretty basic functionality. Apart from styling your div with the gravatar as a bkg image the way you’ve done it is similar to how I ended up getting it to work. The code I used is:
<?php $authorHash = md5(get_the_author_email());
$authorHash = trim($authorHash);?>
<div class="post-thumb mb-0"><img class="img-thumbnail" src="http://www.gravatar.com/avatar/<?php echo $authorHash; ?>?s=128" width="128" height="128" /></div>
I’ll incorporate styling the div background, however what I’m wondering is why we can’t use the get_avatar function that wordpress provides. I mean it does work, but the quality is terrible!
Hi @pajohns
The get_avatar() function is both filterable (you can hook a filter function to it) and pluggable (you can replace it entirely with a function in a plugin), so there’s lots of opportunity for the output to get mangled. I’d ask what plugins you have installed and if any of them might be modifying the avatar output.
Do you get the same poor quality output if you disable all your plugins?
Ross