• I am trying to retrieve an avatar using the following:

    <?php echo get_avatar( get_the_author_email(), 96); ?>

    however the code that this line returns is this:

    <img src="http://www.gravatar.com/avatar.php?gravatar_id=e79af5d67f65c94861fee01562971802&size=40" alt="philip@marketdental.com.au'" height="64" width="64">

    Firstly the height of 64×64 – where did this come from? Also you’ll notice that in the avatar.php file it is passing a size value of 40 in, so even at 64 the image appears very poor quality. If I modify these values to be size=96 and then change the height and width to be 96 then it works fine – just can’t figure out where I’m going wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • @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).

    Thread Starter pajohns

    (@pajohns)

    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!

    Ross Wintle

    (@magicroundabout)

    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

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Problems with get_avatar()’ is closed to new replies.