How to display Custom Gravatar for Guest Users in WordPress

When a guest user or non-member user comment in your blog posts or articles, you may have noticed the mysterious person appearing next to his/her name as an avatar in the comment section. Because of this, most of the people often gets misunderstood the comment as a SPAM !! Although they are relevant and genuine comments, they still look like a Spam. And because of this many visitors ignore the comments. We can, however, have our own custom default gravatar for guest users.  That’s right. With a few lines of simple codes, you can display your own Custom Gravatar for Guest Users. Before beginning, make sure you have your custom image uploaded inside your active theme’s folder. OK , let’s begin !!

What is a Gravatar ?

When you visit different websites sites, you may have noticed the guest users or member users have a picture appearing just next to their name. They are called Avatars. In WordPress, Avatars are generally called Gravatars (Globally Recognized Avatar). If you register with Gravatar and if you comment on the blog posts, the email associated with Gravatar automatically displays your uploaded image on the comment section. And if you haven’t registered with Gravatar and choose to comment in Posts, the default icon will appear next to your name.

So Why use Gravatars ?

  • Extra Plugins are not needed to update every users’ profile image.
  • Gravatars can be used with a very less effort.
  • Users don’t have to register for every site they visit just to use Avatar/Gravatar.
  • More can be done with less efforts.
ALSO READ  Disable or Remove Pings in wordpress

Display Custom Gravatar for Guest Users

Step: 1: Upload your custom gravatar image in any theme’s folder

The very first step is to select your desired custom avatar image and upload to your theme’s img folder. Don’t worry about the resolution of the image. WordPress will automatically resize image to default gravatar dimension once you set your custom gravatar.

(For example:- wp-content→themes→YourTheme→img→batman.jpg )

Custom Gravatar for guest users

Step: 2: Place the below code in your theme’s functions.php file

In your active theme’s functions.php, place the following line of codes and save the file. In below code, I am going to name my custom avatar as Batman Avatar. You can choose your desired name. What about Custom Gravatar ?  Just choose one, that doesn’t get you confused.

add_filter( 'avatar_defaults', 'pp_custom_gravatar' );
function pp_custom_gravatar ($avatar_defaults) {
  $myavatar = get_bloginfo('stylesheet_directory').'/img/batman.jpg';
  $avatar_defaults[$myavatar] = "Batman Avatar";
  return $avatar_defaults;

Step: 3: Change default Gravatar from Dashboard

This is the final step. Login to your dashboard, Go to Seetings→Discussion. On the very bottom of the discussion page, you’ll see Default Avatar option. By default, the WordPress has the Mystery Person as a default Avatar. Select your newly added gravatar i.e. “Batman Avatar” and hit Save Changes.

Custom Gravatar for guest users

And we’re finally done. If you’ve followed the above steps correctly, you’ll see the guest’s avatar as Screenshot Below:

Custom Gravatar for guest users

Final Thoughts

This is just a simple trick without using plugins. There are, however, other available WordPress plugins for Custom Gravatar for Guest Users. Below are some of my favorites: