Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Change the Default Gravatar on WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Change the Default Gravatar on WordPress

Implementation of Gravatar is an uprising trend that is being seen on many WordPress Blogs. More and more blogs are following the trend by incorporating the gravatar. Not only bloggers, but theme designers are also focusing on making the best comment box for their WordPress themes and implementing gravatar with creativity.

While bloggers may know about gravatar and have an account, there are other users who don’t have a personal gravatar, so when they post a comment on a blog, a mystery man takes over their gravatar. You probably have seen it on many blogs, on a gray background a white guy. In this article we share a way to have a custom gravatar for your blog users which you can incorporate in your blog.

Good Bye Mystery Man

As you can see in our comment box, when a user who does not have a gravatar account comments, our wpbeginner logo shows up. You can do the same now. First thing you need to make sure is that your theme have gravatar enabled.

1. Open your functions.php file which is located in your themes folder.

2. Then paste the following code in there

add_filter( 'avatar_defaults', 'newgravatar' );

function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/gravataricon.gif';
$avatar_defaults[$myavatar] = "WPBeginner";
return $avatar_defaults;

You need to understand the variables in the code above.

‘/images/gravataricon.gif’ is the location of the image file. It must be saved under the theme folder that you are using.

Change WPBeginner to the name that you want to give your Gravatar and you should be all set.

3. Upload this file

4. Login to your WordPress Admin Panel and click on Settings > Discussion

Gravatar Settings

Your gravatar now show up like the picture above displays. Select it and save changes, and you are all set.

Now you should be able to change your gravatar in no time.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Manoj says:

    I can’t see my avatar even after setting in comment box but i see it about me.

  2. Michael says:

    I’m looking for a plugin, or SIMPLE code solution that will allow me to create a number of ‘default’ gravatar/avatar images that are color coded based on the member’s gender/orientation. Obvious ones like blue for male, pink for female, but I’ll likely add lavender for transgender and possibly others. Basically, the decision about the ‘default’ avatar that appears for the member (until they upload an image) would at least let people browsing the site know if the person they see posting (or online) is male / female / transgender / etc.. Any ideas?

  3. Me says:

    Is there code to force the default avatar to be blank? I have it set to blank in the WP settings, but it’s still showing up as mystery man. Is there code to either delete mystery man entirely so it’s not even an option. Or to make sure it’s blank and not mystery man? Thanks!

  4. Michael says:

    How would one go about rotating a set of images in that Gravatar thumbnail spot? Meaning: if I had 5 different images, to have them randomly appear for users without Gravatars, so there was a variation of the 5?

  5. Angelica Costa says:

    If anyone is facing issues with child themes, just use:

    $myavatar = get_stylesheet_directory_uri().’/img/favicon.png’;

    It works.

  6. Gina Smith says:

    Thanks for the information!

  7. Keely says:

    Wow – found this post 2 years after my first post and got it working this time :)
    Thanks WP Beginner

  8. Caroline says:


  9. chris007 says:

    okay i get the whole idea but how you put your personal pciture of you into the gravatar that what i’m trying to figure out..

    • Thomas says:

      Goto Gravatar website and sign in with WordPress. Then you can upload your avatar and tie it to one or more of your emails.

  10. Alex says:

    Thank you!

  11. Karan Rawat says:

    It works. Thanks Bookmarked your blog!

  12. Chuks Emmanuel says:

    Thank you Syed Balkhi. it really worked for me. just keep the good work going.

  13. Adrian O'Farrell says:

    Hi, just checking what happens next

  14. Simen Eggen says:

    Thank you so much :) it’s working :D

  15. Sadia says:

    Thank you so much for these instructions. For some reason, things were wonky when I used a .png file, but a gif worked easy peasy!

  16. Katelyn says:

    I am having the same issue as Keely. I am using a child theme so get_bloginfo does not work. When I check the URL of the broken image it displays the path to the parent theme. Is there a way to get this to work with a child theme?

  17. Akash KB says:

    What should be the size of the image file to be uploaded to the theme folder?

    Thanks :)

  18. Brody says:

    Any way to make this use a SSL connection using the same code? Always loads “insecure content”. What changes to make it a secure image during loading?

    • WPBeginner Support says:

      If you are loading gravatar on a secure page then it should automatically load securely. Also check Settings » General change your site and WordPress address to use https. Let us know if this solved the issue.

  19. Pavan Deshpande says:

    Thank you for sharing this , i was not able to change the default image but after reading this i changed

  20. Keely says:

    What if you’re using a child theme …

    I changed the line
    $myavatar = get_bloginfo(‘template_directory’) . ‘/images/gravataricon.gif’;
    $myavatar = get_bloginfo(‘stylesheet_directory’) . ‘/images/gravataricon.gif’;

    but still not working :(

    • Editorial Staff says:

      Is the image not showing or the code altogether is not working (i.e it’s not even adding an option for custom gravatar)?

      • Kristen says:

        I am having issues with the code also. I used it on another site and it worked perfectly, however on the site I’m currently working on… it shows as an option in the admin panel under settings-discussion, however it is showing as a broken image and does not display on the blog pages either. Any help is greatly appreciated.

        • Editorial Staff says:

          Right click on the broken image to get the image URL. Open that URL in another tab to verify that the URL is correct.

        • Dizz Markie says:

          I am having the same issues on localhost

  21. Rachel says:

    I just used your advice here; more explanation that the image needed to be saved in the themes folder too would have been helpful. But your tips here helped me figure some of it out. Thanks.

  22. mrahmadawais says:

    @wpbeginner Secondly , do you know an good pre image loading plugin for wordpress

  23. mrahmadawais says:

    @wpbeginner disquess is having some problems at my blog see there it is not allowing me to upload any custom image>>>? Why

  24. wpbeginner says:

    @mrahmadawais That is because Disqus is a third party platform….

  25. mrahmadawais says:

    tell me plz

  26. mrahmadawais says:

    any one here now to tell me why disquss is not accpting this

  27. Crysislevel says:

    thanx it worked perfectly! :)

  28. Shabil Team says:

    This gravatar custom code is very cool and really work on my blog. Thank you very much.

    You rock WPbeginner.

  29. Shabil Team says:

    This gravatar custom code is very cool and really work on my blog. Thank you very much.

    You rock WPbeginner.

  30. wpbeginner says:

    @Kindar We are glad to have you as a user :) Let us know if you have any suggestions.

  31. Kindar says:

    When ever I search for something on the internet i usually get to see your website.. Now I started follow your website and the stuff you share.. What ever you share its really useful and thats why i always check it up, and see whats new. Also i wanted to thank you for the last subject.

  32. Kindar says:

    When ever I search for something on the internet i usually get to see your website.. Now I started follow your website and the stuff you share.. What ever you share its really useful and thats why i always check it up, and see whats new. Also i wanted to thank you for the last subject.

  33. iur says:

    where is located the file /images/gravataricon.gif ?

  34. Cee says:

    Wow..I’ve gone round and round with code. Not adept with this as a newb…but usually can get things to work.
    I added the code to get a default avatar for guest . It worked. At least in admin. The image shows up in ADMIN..but not on the website.

    I also signed up at gravatar for my own custom gravatar for my ADMIN comments…and it shows up in their “check point”…but cannot get it to show up in my comments.

    Neither does the Guest Gravatar.. but the GRAVATAR image shows up instead.
    My custom image IS checked as default in Discussions. Both images are uploaded to the theme/images and the path to the guest image is correct in the code. I made the images 128 x 128 as suggested online nowadaZe… Dunno if THAT sizing must be specified somewhere? I looked thru the functions code…as best as my bewildered eyes can comprehend..but didn’t finding anything that looked like it would work. Maybe in style.css?… Dunno if it makes a difference. Don’t want to go thru changing everything..and still not work. Have already spent DAYS trying to figure this out. Should be a simple thing.

    Don’t understand why MY admin gravatar isn’t showing. Per what I read…it should be handled via gravatar. The email address used for the gravatar is the same as listed in admin.

    WHAT am I doing wrong/missing?.. I have WP 2.8.4.
    I tried pasting the above code at the top…AND at the bottom… but neither works. Does it matter WHERE you paste it in the functions.php?

    Can you suggest anything?Would DEEPLY appreciate any help you can give. Can give you any code you might need…just specifiy.

    Thank you in advance. tearing out hair..

    • Editorial Staff says:

      It sounds like that this issue is not with the function rather it is the comments.php file error.

  35. Louis Gubitosi says:

    thanks for this tip. I used this on my site and the default avatar is showing up in the comments section but not in the “Recent Comments” side bar. I’m using the “Get Recent Comments” plugin. Is this treated differently?

    • Editorial Staff says:

      Unless that plugin has specified a default in their code, this should work. It means the plugin is not coded properly. Contact the developer, and ask them to fix it.

  36. martin says:

    The code works if placed in custom-php.php which has the advantage of sticking through upgrades.

    Do you have any ideas on the code for removing the html calls to in buddypress?

  37. JD says:

    Thanks for the tip. Works flawlessly.

  38. Desik says:

    I noticed wordpress is changing the quote into a backquote, you should use ' instead of

  39. fantasmo says:

    This is the code snippet I was looking for.
    But it doesn’t work properly… I put in the code into my functions.php (I’m sure everything is correct, also the path to my picture).

    But when I go to discussion, I can’t see my Avatar, and also the WP-backend is a little bit broken… The code i put into the functions.php shows up above the header of the WP-backend.

    Can you help me please? Maybe I didn’t only a little thing wrong??

    • Editorial Staff says:

      The code above is 100% correct because that is what we are using. I don’t know what you can potentially be doing wrong. But without looking at your codes we won’t be able to help you out. You can hire us for a small fee, and our staff can surely fix the problem.

      • Tracy says:

        I think I may be having the same trouble as fantasmo. The snippet works and the gravatar shows up within the discussion admin page but when you click on ‘save changes’ to save the options, you get a white screen which displays the footer from the option-discussions.php instead of the full page saying that the options have been saved.

    • CC Rogers says:

      I saw the same results as Fantasmo. When I copy/pasted the code, the blank line between the add_filter and the function was lost for some reason. Putting the blank line back seemed to fix the problem.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.