WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jan 23 2012

How to Add an Avatar To WordPress Defaults, Remove Default Avatars, & Set Your Default

With WordPress and Genesis, Avatars are used as identification (like the Twitter icon), and with Gravatar it is in the comment area and the User Profile Widget.

Default Avatars
Click for larger image

WordPress allows the user to set a default or generated Avatar, if the commentator doesn't have one. However, I find these options rather ugly or not fitting to the theme most of the time.

Add an Avatar to WordPress Defaults

So I'd like to show you how to add an avatar to the WordPress defaults.
[php]
// Add Custom Avatar (Discussion Settings)
add_filter( 'avatar_defaults' , 'wps_new_avatar' );
function wps_new_avatar( $avatar_defaults ){
$new_avatar = get_stylesheet_directory_uri() . '/images/genesis-48x48.png';
$avatar_defaults[$new_avatar] = "Genesis";

return $avatar_defaults;
}
[/php]

Add New Avatar
Click for larger image

Remove Default Avatars from WordPress Defaults

For those of us who don't care for some of the WordPress defaults, within that function you can easily remove them at your will:
[php]
// Add Custom Avatar (Discussion Settings)
add_filter( 'avatar_defaults' , 'wps_new_avatar' );
function wps_new_avatar( $avatar_defaults ){
// Get Avatar from child theme images folder
$new_avatar = get_stylesheet_directory_uri() . '/images/genesis-48x48.png';
$avatar_defaults[$new_avatar] = "Genesis";

// Remove default avatars
unset ( $avatar_defaults['mystery'] );
//unset ( $avatar_defaults['blank'] );
//unset ( $avatar_defaults['gravatar_default'] );
//unset ( $avatar_defaults['identicon'] );
//unset ( $avatar_defaults['wavatar'] );
//unset ( $avatar_defaults['monsterid'] );
//unset ( $avatar_defaults['retro'] );

return $avatar_defaults;
}
[/php]

Remove Avatars
Click for larger image

Set Your Default

Now, WordPress gladly will set your default avatar to the well-known, popular Mystery Man. However, instead of navigating to Settings > Discussion, you can easily set your default as well.
[php]
// Set new avatar to be default
add_action ( 'admin_init' , 'wps_avatar_default');
function wps_avatar_default () {
$default = get_option('avatar_default');
if ( ( empty( $default ) ) || ( $default == 'mystery' ) )
$default = get_stylesheet_directory_uri() . '/images/genesis-48x48.png';
update_option ( 'avatar_default' , $default );
}
[/php]
The known downside of this is that now, Mystery Man can never be chosen so long as this code is active (so it would work well to remove Mystery Man (unset ( $avatar_defaults['mystery'] );) above. This way you can easily control the avatars on your site.

Final Avatar
Click for larger image

Written by Travis Smith · Categorized: Genesis, WordPress

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Will Jackson says

    February 15, 2013 at 11:22 am

    Hi – I couldn’t get your gravar replacement code to work, the image was displaying as broken, and was still referencing the gravatar url – shame as this would be a really useful technique, sorry I can’t offer a fix.

    Reply
    • Stijn says

      November 26, 2014 at 9:41 am

      I just found out that the gravatar image should be available online. Had trouble with it locally myself, ran into the same issue. So i uploaded the image, reference the publically available location and the image shows.

      Reply
  2. Mike Hemberger says

    December 2, 2014 at 2:30 pm

    Same issue as Will Jackson here. Strange thing is, I’ve used this code before.. this time it’s not working though.

    Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in