WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm trying to add a new default avatar for my theme using the following code:

add_filter( 'avatar_defaults', 'mytheme_default_avatar' );

function mytheme_default_avatar ( $avatar_defaults ) {
    $new_avatar_url = get_template_directory_uri() . '/images/default_avatar.png';
    $avatar_defaults[$new_avatar_url] = 'Default Avatar';
    return $avatar_defaults;

After I do that, the new avatar appears on the administration, but it's not checked by default. Is there any way I can manipulate that admin option via functions.php? It's essential, since I have different color skins in my theme and I use different avatar images for each of them.. So once the user change the color skin, another default avatar will appear and the option will change itself again (since the old image will be gone).

So basically I'm looking for a way to change the "Default Avatar" option under "Settings -> Discussion" via functions.php in a natural way. Hope that makes sense.

Thanks in advance!

share|improve this question
up vote 1 down vote accepted

You can just update the option field avatar_default to your new image url:

add_filter( 'avatar_defaults', 'mytheme_default_avatar' );
function mytheme_default_avatar( $avatar_defaults ) 
    $avatar = get_option('avatar_default');

    $new_avatar_url = get_template_directory_uri() . '/images/default_avatar.png';

    if( $avatar != $new_avatar_url )
        update_option( 'avatar_default', $new_avatar_url );

    $avatar_defaults[ $new_avatar_url ] = 'Default Avatar';
    return $avatar_defaults;
share|improve this answer
Awesome! Thanks! – ZK_ Jul 26 '13 at 12:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.