WordPress Code Snippets

A fresh mix of code snippets and tutorials

Display a custom gravatar in WordPress

30

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

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!