Post Pic

How to: Add new Gravatars to WordPress default gravatar list

WordPress allows you to choose a default gravatar to be displayed on your comments when the commentator don’t use Gravatars. But what if you wan to add more avatars to the list? That’s easy: simply apply this simple method.

Simply paste this code on your functions.php file. Don't forget to change paths to the images in the code.

if ( !function_exists('fb_addgravatar') ) {
	function fb_addgravatar( $avatar_defaults ) {
		$myavatar = get_bloginfo('template_directory').'/images/avatar.gif';
                //default avatar
		$avatar_defaults[$myavatar] = 'people';

		$myavatar2 = get_bloginfo('template_directory').'/images/myavatar.png';
                //Avatar for user "admin"
		$avatar_defaults[$myavatar2] = 'admin';

		return $avatar_defaults;
	}

	add_filter( 'avatar_defaults', 'fb_addgravatar' );
}

Thanks to WpEngineer for this great hack!

Related Posts

Related Posts

No related posts.

8 Responses

Jan 24 2009 19:47

Awesome! I saw another way to do this that was much more complex, so this takes the cake. I’m surprised this functionality isn’t already built into the WP admin.

Jan 25 2009 00:17

That is a very nice little recipe!

Feb 24 2009 05:30

Where so I add this in fuctions.php? I added it to the end, but it didn’t work

Jun 08 2009 08:14

Make sure you add it within the tag my friend.

Nov 09 2009 22:09

Reallt helpfull thanks! ;)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required