Add a custom default avatar to your WordPress site

WordPress have a built in support for gravatars which means that WordPress will automatically fetch the avatar associated with the commenting users email address. If the email address is not associated with an avatar WordPress will display a default avatar. You as a site owner can choose between a set of default avatars but you can also add your own custom avatar. Choose default avatar from the discussion page under the settings menu.

WordPress Default Avatars

WordPress Default Avatars

How to add a default custom avatar

To add a custom avatar, place the following code in your functions.php located in your theme folder.

add_filter( 'avatar_defaults', 'new_avatar' );
function new_avatar($avatar_defaults) {
	$new_avatar = get_stylesheet_directory_uri() . '/images/custom-default-avatar.png';
	$avatar_defaults[$new_avatar] = "Site name";
	return $avatar_defaults;
}

“Site name” is the text to the right of the avatar in the image above. Change it to something appropriate. Also, don’t forget to add the image to the images directory.

About Fredrik Malmgren

Fredrik Malmgren is an entrepreneur, project manager and developer specialized in WordPress. Read more about me or get in contact with me. You can also find me on Twitter. (@fredrikmalmgren).
This entry was posted in Tutorials, WordPress and tagged , , , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>