Tag Archives: avatar

Adding Avatar to WordPress Default

24 Aug

Adding Avatar to WordPress Default

Introduction

In WordPress, there is a nice solution via a hook, which enables to add an avatar in the list of your backend and to make a selection to our own styled avatar. In the following section I like to show a simple code snippet which explains how to add new avatar to the array of WordPress.

You have to add the snippet shown in the screenshot to functions.php of your theme and it will add Avatar from your images folder of your theme directory.

When the theme becomes active, you will have two new Avatars available in your list.


#adding our own avatar

function own_gravatar($avata_defaults) {

$my_avatar = get_bloginfo('template_directory').'images/our_gravatar.jpg';

$avatar_defaluts[$my_avatar]="Our Avatar name";

return $avatar_defaults;

}

add_filters('avatar_defaults','own_gravatar');

How to do

own_gravatar() function provides the location of the image which is in the images folder of the WP installation directory and assigns a name Our Avatar name to it. And finally the output is sent back to default avatars (avatar_default) which displays the gravatar in the default gravatar list in the dashboard.

Now go to your Dashboard->Setting->Discussion. Scroll down the page and select your new default gravatar. And you are done.

You can customize the look’ by editing the style properties for gravatar class in the style.css file.