How to Change the Default Gravatar on WordPress
Gravatar, a common thing that we are seeing implemented in many blog designs. While I am working on the free theme for you guys, I thought maybe it is better to brand the theme with a custom gravatar for the users as well. Customized gravatars help you brand your site even more. Well I personally did not know of any way to change this, so I looked on the web for tutorials. I found two different tutorials, and they both work. There are advantages to use both, so I will share them with you.
First Method: By editing the Comments.php File
Michael at Problogdesign came up with this tutorial.
First you need to open up your comments.php file, or legacy.comments.php file if you are using that.
Find this code:
<?php echo get_avatar( $comment, 60 ); ?>
Note: You might not have the 60 because different themes come with different sizes for the gravatar.
You need to replace this code with your own created image code as follow:
<?php echo get_avatar( $comment, 60, ‘http://www.balkhis.com/wp-content/themes/yourthemename/images/youravatar.png’); ?>
Remember to change the url to the correct path. Now if you want to understand the code basically it is calling this image as you default avatar when you put that link unless a user already have a gravatar.
And the 60 represent the size in pixels which is why I said it won’t be the same in each theme. You may change the size of it to fit your theme.
Now this is for people who like to have raw codes, but if you are releasing this theme out for free, then it won’t be the best choice because people can really screw with the codes if they mess things up accidently.
Step 2: Editing the Functions File
This is another tutorial that I found on the web which is basically a plugin in a non-plugin form. I found this code at Build Internet. Basically in this plugin you are editing your functions.php file
add_filter( ‘avatar_defaults’, ‘newgravatar’ );
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo(‘template_directory’) . ‘/images/buildinternet-gravatar.jpg’;
$avatar_defaults[$myavatar] = "Build Internet";
return $avatar_defaults;
}
By adding these codes you are telling wordpress that there is another image that you like to be seen. So once you add this code, you will see an image in your admin panel.
You can even have more than one default gravatars if you want to give more options. Just simply duplicate the $myavatar variable multiple times, and you will have it.
The advantage of this code is that it is easier for users who are not coders because they don’t have to look a whole lot to change.
I will let you make the pick.
Now you should be able to change the default mystery man avatar to your personal branded new avatar logo. Thanks to these two fellas for providing us with the options.





















Hey, I am Syed Balkhi, The guy who is behind Balkhis Inc. I entered the industry back in 2002 not knowing a single thing. I barely spoke English at that time. In the past six years, my language barrier has been eliminated. Aside from English, now I also speak html, and php. Along with the languages I have also managed to master a few arts. Art of web-designing started when I first entered. Messing around with photoshop, I learned how to create my first web design. Now I founded a web designing firm Uzzz Productions. After running numerous amount of websites in various niche, I have mastered the art of web-development. Now I am compiling a resource of what I already know, and what I am learning on this blog. This resource is to help me if I ever need a guide to look back to, and it is help my fellow webmasters.




NIce post,
Will try it out
When are you going to add avatars to your blog posts. They don’t serve much of a purpose but they can be fun to look at.
Thanks, I’ll try that in the near feature.