How to add custom avatar in WordPress

Gravatar has become really easy to use custom avatars across multiple platforms. What if your users don’t use Gravatar or have an avatar, a default avatar is loaded in it’s space. It is recommended you brand your default avatar to your website.

First, lets make sure you have a custom avatar image ready. If you do not, make one in the dimensions of 64×64.

Second, name your avatar whatever you want, let’s say “custom-avatar.jpg”. It’s entirely up to you to name it what you want.

Thirdly, upload your image to wp-content/themes/your-theme/images/.

Lastly, open wp-content/themes/your-theme/functions.php and add the following:

// Adds a custom default avatar
if ( !function_exists(‘fb_addgravatar’) ) {
function fb_addgravatar( $avatar_defaults ) {
$myavatar = get_bloginfo(‘template_directory’) . ‘/images/custom-avatar.jpg’;
$avatar_defaults[$myavatar] = ‘Your Name’;
return $avatar_defaults;
}
add_filter( ‘avatar_defaults’, ‘fb_addgravatar’ );
}

Note: Replace “custom-avatar.jpg” with whatever you named it. Also replace “Your Name” with a name to describe the image – this is normally your website name.

Now go to Settings —> and click on “Discussion”, you will be able to see the custom avatar you just added. You can now choose the newly added custom avatar as the default avatar shown.

Author: Ryan Kessen

Computer Repair, Freelancer, Blogger, Reviewer and all around nice guy!

Leave a Reply

Your email address will not be published. Required fields are marked *