Adding Custom Default Gravatars to Your Blog

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’.

About Rae Hoffman

Rae Hoffman aka "Sugarrae" is an affiliate marketing veteran and the CEO of PushFire, a search marketing agency specializing in SEO audits and link building strategies. She is also the author of the often controversial Sugarrae blog. You can connect with Rae via Twitter, Google+ and Facebook.

Sugarrae runs on the Genesis Framework

Genesis Framework

If you’re someone who doesn’t understand a lot of PHP, Genesis will give a ton of functionality that you wouldn’t be able to obtain otherwise with a simple control panel instead of having to alter code. For the advanced, Genesis has incredible customization possibilities via Genesis hooks.

The theme is not only highly customizable, but it has allowed me to run Sugarrae more professionally, with a much more targeted focus on monetization than it ever has been able to achieve before.

You can find out more about Genesis below:

Speak Your Mind

*