Site logo

Archived topic

Author Box image

5 replies · Started by Rachel on March 18, 2020

Viewing posts 1–6 of 6

Hi,
I have set up an author box using code found on the support forum. I want to switch avatars off for people who post comments, but when I do that, it also removes the image from my author box.

Is there a way for the author box code to pull my gravatar for the author box without having avatars switched on for comments?

Thanks,
Rachel

Hi there,

leave the Avatars enabled in the Discussion settings, and add this PHP snippet to your site:

function disable_comment_avatar($avatar, $id_or_email, $size, $default, $alt)
{
    global $in_comment_loop;

    if(isset($in_comment_loop))
    {
        if($in_comment_loop == true)
        {
            return "<img alt='{$alt}' src='' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
        }
        else
        {
            return $avatar;
        }
    }
    else
    {
        return $avatar;
    }
}

add_filter("get_avatar" , "disable_comment_avatar" , 1, 5);

Hi David,

What does this code return instead of an avatar?

Also, where do I place the php? Can I add it to a hook or does it need to be added somewhere else?

Thanks
Rachel

Thanks David - works a treat.

You're welcome

This archived topic is closed to new replies.