[Resolved] Author Box image

Home Forums Support Author Box image

This topic contains 5 replies, has 2 voices, and was last updated by  David 2 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1199098

    Rachel

    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

    #1199266

    David Customer Support

    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);
    #1199272

    Rachel

    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

    #1199277

    David Customer Support

    It should return nothing in the Comments loop but still allow the Author avatar to be displayed.

    Can’t use Hooks for this piece of code – this article explains adding PHP:
    https://docs.generatepress.com/article/adding-php/

    #1202225

    Rachel

    Thanks David – works a treat.

    #1204726

    David Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.