Dark Mode On / Off

How to change the Default WordPress Gravatar image?

How to change the Default WordPress Gravatar image? 1

Gravatar, a web service, is a cool feature available in WordPress run by WordPress co-founder Matt Mullenweg’s company called Automattic. It allows the user to create a profile and associate avatar images to their email address along with a short bio.

The Gravatar image is displayed on WordPress blogs where the users write a blog post or leave a comment. But, it has a downside. It affects your site performance while making external HTTP requests to get the image to display them on your site. The more HTTP requests you send, the slower your site loads.

So, if you want to improve your site performance, you can avoid a request for Gravatar and host them locally which will improve your site loading time.

If the user doesn’t have a Gravatar image, then WordPress automatically shows the default Gravatar image. The default image set is called a mystery man and it looks like this:

How to change the Default WordPress Gravatar image? 2
Default WordPress Gravatar image

If you don’t like the default image, you can change it to a different one from the available options or host them locally.

Changing Default WordPress Gravatar Image

To change the default Gravatar image, from your dashboard go to Settings > Discussion page and scroll down to Avatars section. You can configure the Avatar settings and change the Gravatar image from the list of available ones.

How to change the Default WordPress Gravatar image? 3
Changing Default Gravatar Image in WordPress

There are only a few choices available under the default avatar options. The avatar is used when a user doesn’t have a Gravatar associated with their email address. You can choose the one you like and save the changes for the immediate effect.

However, you are not limited to using this default Gravatar image. You can upload your own images to host them locally with your own brand image.

Using a Custom Default WordPress Gravatar Image

WordPress allows you to disable default Gravatar and upload your own images, which will be hosted locally along with your other media. There are two ways you can upload your own Gravatar image:

#1. Changing Custom Default WordPress Gravatar Image using a plugin

At first, you need to install the plugin WP User Avatar from Plugins > Add New.

How to change the Default WordPress Gravatar image? 4
Installing WP User Avatar plugin

Once you have activated the plugin, click on Avatars menu located on your dashboard sidebar to access the plugin settings.

Under the settings, check the Disable Gravatar and use only local avatars box. Few settings will disappear after you enable this option.

How to change the Default WordPress Gravatar image? 5
Disable Gravatar and use only local avatars

If you click on the Save Changes button and check your site, the default image will be replaced by this new avatar. This new avatar will appear by default for both non-registered and registered users.

You can also upload your custom avatar by editing your user profile via Users > All Users. You will find the Avatar section at the bottom.

How to change the Default WordPress Gravatar image? 6
Changing user profile avatar

The plugin also includes an option to Allow Contributors & Subscribers to upload avatars. Once you enable this option, you will see an option to set the max upload file size and dimensions.

How to change the Default WordPress Gravatar image? 7
Enabling Allow Contributors & Subscribers to upload avatars option

Here’s the preview of how it looks with different avatars.

How to change the Default WordPress Gravatar image? 8
Comments with different avatars

#2. Modifying the code

The other approach is to modify the default image by modifying your theme’s functions.php file. I suggest you create WordPress child theme for your site since you want to retain the changes even after updating the parent theme. I try to minimize the use of plugins so with this approach you don’t need to use any plugin.

At first, you need to create a square image like 200x200px that you want to use as your default Gravatar. Once you create that image, you need to upload this image to your WordPress site. To upload your custom default Gravatar image, go to Media > Add New.

How to change the Default WordPress Gravatar image? 9
Uploading Custom WordPress Gravatar image

After the image is uploaded, you need to click on the Edit link next to the image. WordPress will open your image for editing. You have to just copy the image URL and paste it in plain text editor like Notepad.

How to change the Default WordPress Gravatar image? 10
Uploaded Gravatar Image URL

Now, open your child theme’s functions.php that you have created earlier referring to the above guide. In the functions.php file, paste the below code.

add_filter( 'avatar_defaults', 'wphelpguide_new_gravatar' );
function wphelpguide__new_gravatar ($avatar_defaults) {
    $avatar = 'https://wphelpguide.com/wp-content/uploads/2019/09/wphelpguide-gravatar.png';
    $avatar_defaults[$avatar] = "Default Gravatar";
    return $avatar_defaults;
}

Don’t forget to replace $avatar value to the URL of the custom Gravatar image that you uploaded earlier. Save the code and activate the child theme.

When you go to Settings > Discussion, you will notice your custom default avatar added in the list of avatar choices.

How to change the Default WordPress Gravatar image? 11
Selecting custom Gravatar image

Now, select your custom default avatar image that you have uploaded and then click on the Save Changes button.

WordPress will now use your image as default WordPress Gravatar image for users who don’t have their Gravatar image associated with their email address.

How to change the Default WordPress Gravatar image? 12
Changed default Gravatar image

Final Thoughts

I hope this article helped you learn the technique to change the default WordPress Gravatar image. You can go with either of the approaches but using the plugin will be much easier.

If you face any issues or have any questions, do feel free to comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Recommended Articles