Aside from the standard Gravatar, WordPress allows users to choose from a list other default avatars. If you are creating your own theme, you can add an avatar or icon consistent with your theme’s styling to the list of default choices.

WordPress makes this a rather simple endeavor with the avatar_defaults filter. Add the code snippet below to a callback function (replace themeslug_ with your theme’s function slug) add an image of your choice to the list of avatars users can select from.

Although you can use any size, avatars of 60×60 pixels are the generally accepted size.

Code

// custom callback function
function themeslug_addgravatar_cb( $avatar_defaults ) {
	$theme_image = get_stylesheet_dir_uri() . '/img/avatar.png';
	$avatar_defaults[$theme_image] = 'avatar name';
	return $avatar_defaults;
}

// filter call
	add_filter( 'avatar_defaults', 'themeslug_addgravatar_cb' );

You now have a custom avatar!

Leave a Reply

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

Post Navigation