top-arrow

How to Change Gravatar Image size in a WordPress site

change gravatar image size

Gravatar is used globally. It shows your image beside your name when doing things like comments, post on a blog site. Gravatar supports in popular applications like WordPress as well as others too. So it’s necessary to change gravatar image size in WordPress sometimes.

Most of the WordPress Themes show gravatar images left side of the comment section. If your Theme doesn’t have this one, then you can use WordPress plugin to show your gravatar image such as you can use WP Author Bio Plugin for that.

 

Let’s drive on how to change gravatar image size in your WordPress site.

First of all what you need to do is to find comments.php in your Themes. So you’ll need to use FTP or File Manager to do that because these tools will allow you to access your file.

This file can be found in your Theme directory ( wp-content/themes/your-activated-theme ) .

If you get the file then open it in a code editor or you can use notepad. And try to find a function called wp_list_comments  function, it takes an array as a parameter. Given an example bellow.

        wp_list_comments( array(
            'avatar_size' =  50,
            'max_depth'   =  5,
            'style'.      = 'ol',
            'short_ping'. =  true,
            'type'.       = 'comment',
        ) );

As you can see there is a key of that array called ‘avatar_size’ so what you can do simply change the value as you want. It’ll change gravatar image size. It sets both the width and height of your gravatar image. So if you change it then that’ll be affected in front-end.

After saving your code check this out in front-end it’s working or not. If it works then you’re good to go. Or you’ll need to check css code of your Theme.

Because your Theme’s css is overriding the size. So to check this out, Go to any blog post of your site and in comment section use inspect element tool of chrome if you’re using chrome browser but if not you can use your default browser.

After that find out that any css code is overriding the default gravatar image size or not. As you see I’ve given an example below. And my Theme’s css is not letting me change Gravatar Image size in my WordPress site.

Your Theme definitely has this kind of codes that preventing to change gravatar image size in your WordPress site as well.

So to change gravatar image size what you can do is overriding the css code. To do this you’ll need to open style.css  of your Theme.

You’ll find it in your Theme directory ( wp-content/themes/your-activated-theme/style.css )

So open it and past the code below.

.comment .avatar {
    width: 50px;
    height: 50px;
}

Now it should work after saving your code. If you can’t see the updates just clear your browser cache and reload your page or check this out in an incognito window.

Note: you can use your height and width as you want.

I will recommend not to use big image size. Because it will look like blurry.
Also, it can affect your page speed. So it’s better to use small size.

That’s all to change gravatar image size in your WordPress site.

 

How to change gravatar image size in the author bio.

Actually, it depends on the Theme you’re using currently. Because they can use this different way.

Such as if you’re using WordPress default Twenty Seventeen Theme, then you can change gravatar image size with a filter hook.

Here is how :

function webextent_change_author_bio_image( $default_size ) {
    $default_size = 50;
    return $default_size;
}
add_filter('‘twentysixteen_author_bio_avatar_size', 'webextent_change_author_bio_image');

Paste the code in your Theme’s functions.php and save. You can set your value as you want.

Note : Other Themes may use this get_avatar( get_the_author_meta( ‘user_email’ ), 32);

So you’ll need to find out the code and file and simply change the value.

I hope that you like this article. If you would like to know about WordPress security then you can check this out here : 10 important tips for WordPress security

Tags:

0 comments

Leave a Reply

Mohammad Rahat
about me

Mohammad Rahat Tanjid

Mohammad Tanjid is a professional WordPress Developer and Designer, he builds WP Products like WP Themes/Plugins and author of webextent.net. He has been writing code for more than 5 years now.