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.
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!
7 Responses
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.
That is a very nice little recipe!
Where so I add this in fuctions.php? I added it to the end, but it didn’t work
Make sure you add it within the tag my friend.
Reallt helpfull thanks!
Trackbacks: