How to change the default Gravatar in WordPress

You can give your comments section a more personalized look by setting a custom gravatar for your WordPress blog, and you don’t need a plugin to do it. When a user who has not signed up for a gravatar posts a comment on your site you’ll now have a custom image instead of the mystery man or worse, the ugly blue G.

Create your custom avatar image and upload it to your theme image folder. Next, paste the following code in your themes function.php file and save.

add_filter( 'avatar_defaults', 'newgravatar' );  

function newgravatar ($avatar_defaults) {
     $myavatar = get_bloginfo('template_directory') . '/images/guest-gravatar.png';
     $avatar_defaults[$myavatar] = "Guest";
     return $avatar_defaults;

Be sure you changed “guest-gravatar.png” to the file name of your avatar.

Now, login to your admin panel and go to Settings > Discussion and select your custom avatar.

Voila! Have a peek at your comments and you’ll see your custom avatar used on comments posted by users with no gravatar enabled.

Like this post? I would love to hear from you in the comments…

One Comment

Leave a Reply

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