Default Gravatar – How To

Okay, so we are all tired of the “mystery man”, or at least those of us that use WordPress.

Here is a way to add your own icon and utilize the admin features according to whether your users or contributors are using gravatar.com.

First, each Worpress theme should come with a functions.php file within it. If you are using THESIS, you may be using a custom_functions.php. Either/or, that is the one that is going to be spinning its magic.

Step one. Let’s create your own custom avatar. Open Photoshop and get busy….this is what I came up with. Sized around 300px x 300px. Used the default #000 for background and #fff for the foreground. A bit of dropshadow and added some bevel (up) to it.
default-avatar

Step two. Let’s get it into the images folder so that when we get into the admin functions we can find it and display it. You can simply add it into your themes /images folder, upload the original (as it gets crunched for you). Open up your themes functions.php file in your favorite text editor and add this code:

1
2
3
4
5
6
add_filter( 'avatar_defaults', 'my_new_gravatar' );
function my_new_gravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/default-avatar.jpg';
$avatar_defaults[$myavatar] = "This is the one!";
return $avatar_defaults;
}

The ‘add_filter’ simply tells the wp-core that we are adding a default function for the site.
The function we are adding here simply tells wp that where to find the image and what to title it “This is the one!”
Then we tell wp-core to also keep the old ones too with the return, and end.

Now that you have that done, save and close the file. Go to your admin dashboard > Settings > Discussion and head to the bottom of that page. You will see your new avatar there. Select it > update settings > and that becomes your default, in case your user and contributors do not have a gravatar already set up.

It will look like this:  

Now, you will no longer see the “mystery man” but rather your own unique custom default. It is that simple.

show off your talents and what you have accomplished by commenting here and sharing your link so that we can all view your work…

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>