apply_filters( 'avatar_defaults', string[] $avatar_defaults )

Filters the default avatars.


Description Description

Avatars are stored in key/value pairs, where the key is option value, and the name is the displayed avatar name.


Top ↑

Parameters Parameters

$avatar_defaults

(string[]) Associative array of default avatars.


Top ↑

Source Source

File: wp-admin/options-discussion.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Rafa Carvalhido

    Put the image address on the key and a title for it on the value.

    function wpdocs_new_gravatar( $avatar_defaults ) {
    	$new_default_avatar = 'https://mysite.com/wp-content/uploads/user.jpg';
    	$avatar_defaults[ $new_default_avatar ] = 'Default Gravatar I chose';
    
    	return $avatar_defaults;
    }
    add_filter( 'avatar_defaults', 'wpdocs_new_gravatar' );

    After that, you must go to Settings >> Discussion > Default Avatar and you’ll see the new image in the bottom of options for gravatar. Select it and save changes.

    You can see the new avatars in action going to Edit Users admin sreen.

Top ↑

You must log in before being able to contribute a note or feedback.