You may have noticed that the default avatar on the Sugarrae blog for folks not registered with Gravatar is not the typical default Gravatars. Instead, it’s a grayed out replica of the bullhorn in the Outspoken logo.
Quite a few folks have asked me how we’ve done this, so I figured I’d give a mini tutorial for both regular theme users and Thesis users.
Regular Themes Via Comments.php
You’ll need to find the following code in the comments template of your theme:
<?php echo get_avatar( $comment, 40 ); ?>
and replace it with the following:
<?php echo get_avatar( $comment, 40, ‘http://www.YOURDOMAIN.COM/wp-content/themes/YOUR-THEME-NAME/images/YOUR-CUSTOM-GRAPHIC-HERE.jpg’); ?>
Once your done the change, you’ll need to save the comments file and ensure your custom graphic has been uploaded to the assigned destination. Because this will be specific to your current theme design, you’ll need to re-add this code should you change designs in the future as with any other theme edits.
Regular Themes Via Functions.php
Note that this code does not require you to edit your blog theme files, so if you change themes later, the code should still work providing the theme supports it. However, you will be editing core WordPress files, so a word of caution. Open your functions.php file (this is NOT Thesis instructions, see further down in the post for those) and add the following code:
add_filter( ‘avatar_defaults’, ‘custom_gravatar’ );
function custom_gravatar ($avatar_defaults) {
$myavatar = get_bloginfo(‘template_directory’) . ‘http://www.YOURDOMAIN.COM/images/YOUR-CUSTOM-GRAPHIC-HERE.jpg’;
$avatar_defaults[$myavatar] = ‘NAME-YOU-GIVE-YOUR-AVATAR’;
return $avatar_defaults;
}
Upload the edited functions.php file and add the graphic you named in your code to the /images/ folder on your root domain. Next, head to your wp-admin panel and click on Settings > Discussion and click the radio button next to the custom default Gravatar you just added.
While this way of adding a custom Gravatar prevents you from having to re-add the code to new themes should you change your current one, you are editing a core WordPress file and will need to re-add the code whenever you do a WordPress update.
Thesis Instructions
Thesis users simply need to open their custom_functions.php file and add the following hook (if you’re not familiar with hooks, you can learn the basics here):
/* Add a Custom Default Gravatar */
if ( !function_exists(‘custom_gravatar’) ) {
function custom_gravatar( $avatar_defaults ) {
$myavatar = get_bloginfo(‘template_directory’) . ‘/custom/images/YOUR-CUSTOM-GRAPHIC-HERE.jpg’;
$avatar_defaults[$myavatar] = ‘NAME-YOU-GIVE-YOUR-AVATAR’;
return $avatar_defaults;
}
add_filter( ‘avatar_defaults’, ‘fb_addgravatar’ );
}
Upload the edited custom_functions.php file and add the graphic you named in your code to the /custom/images/ folder. Next, head to your wp-admin panel and click on Settings > Discussion and click the radio button next to the custom default Gravatar you just added.
The advantage to using Thesis over regular blog themes here is that you won’t need to redo this anytime you change layouts (as with the first one via comments.php file) or when WordPress has an update since your code is located in the Thesis custom files and not your core WordPress files. Just sayin’.



