Add new Gravatars to WordPress default gravatar list

January 25, 2009 · Print This Article

Avatars are popular as identification and with the service Gravatar it is largely used in the comment area of different applications.

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.

Various themes have a standard Avatar to match the design. But even here there is a nice solution via a hook, which enables to add an avatar in the list of your backend to make a selection quite simple.

You have to add this little function to functions.php of your theme and it will add 2 Avatar from your folder images of your theme directory. I suggest, that the Avatars have a size of 60 pixel.

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' );
}

Is the theme active, you will have the 2 new Avatars available in your list.


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.