Balkhis - Vision For Success

How to Change the Default Gravatar on Wordpress

Dear Readers, I would like to thank you for reading this post. I highly value your feedback and would like to know more about my readers. Follow me on Twitter

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.



To stay updated with the blog, please consider subscribing to my full feed RSS. You can also subscribe by Email and have new posts sent directly to your inbox. I hate spam as well, so I promise you that you will not be spammed.
Add to Social Bookmarks:
Add this Article to Digg Add this Article to Stumbleupon Add this Article to Del.icio.us Add this Article to Reddit Add this Article to Newsvine Add this Article to Technorati

RSS feed

3 Comments

Comment by instant cash blog
2009-05-01 06:05:44

NIce post,
Will try it out


 
2009-05-01 08:38:53

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.


 
Comment by Webkinz Subscribed to comments via email
2009-05-02 00:37:53

Thanks, I’ll try that in the near feature.


 

Sorry, the comment form is closed at this time.

Subscribe to Balkhis via RSS
Subscribe to Balkhis via Email Pimp My Blog