WP-Mix

A fresh mix of code snippets and tutorials

Display a custom gravatar in WordPress

Using your own custom gravatars (aka avatars) in WordPress is a piece of cake.

Just add the following snippet to your theme’s functions.php file:

function display_gravatar($avatar_defaults) {
	$myavatar = get_bloginfo('template_directory') . '/images/custom-gravatar.png';
	$avatar_defaults[$myavatar] = 'My custom gravatar';
	return $avatar_defaults;
}
add_filter('avatar_defaults', 'display_gravatar');

Make sure you upload your custom gravatar image to the indicated directory and edit “My custom gravatar” to something that meets your needs.

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress