Wednesday, May 14, 2014

How to Set Your Own Default Gravatar in WordPress

You have seen it in most WordPress blogs: If the commenter’s profile does not come with its own gravatar, the Mystery Man icon is shown instead. Kind of ugly, isn’t it?
What if you can add your own custom gravatar and make it show up in the comments, won’t that be a good way to beautify your blog as well as brand yourself?
Luckily, in WordPress, this can be easily done. You might need to dabble into some coding, but I assure you that it is just a matter of copy/paste the code into the correct files and some minor editing. Follow along and we will guide you through.

1. Create your own custom gravatar, preferably of the size 64 x 64px.
2. Using a FTP program, log on to your server. Navigate to the active themes folder (wp-content -> Themes -> your themes folder). Check if a “images” folder exists. If not, create it.
3. Upload your custom gravatar to the images folder. To check if it is working, on the browser, your custom gravatar should be accessible via the URL:
http://your-site-url.com/wp-content/themes/your-active-theme/images/custom-gravatar-filename.jpg*
* Change the “your-site-url” to your domain name. Change “your-active-theme” to the name of the theme that you are currently using. Change “custom-gravatar-filename.jpg” to the name of your custom gravatar file.
4. Next, download the functions.php file to your desktop and open it with a text editor. Add the following code to the end of the file.
function add_custom_gravatar ($avatar) {
$custom_avatar = get_bloginfo('template_directory') . '/images/name-of-your-custom-gravatar.jpg';
$avatar[$custom_avatar] = "Gravatar name to be shown in the WordPress settings"; //change this name to your preferences
return $avatar;
}
add_filter( 'avatar_defaults', 'add_custom_gravatar' );
5. Save and close the functions.php file. Upload and overwrite the file in the server.
6. Log into your WordPress dashboard as the administrator and go to Settings -> Discussion. You should see your custom gravatar ready for selection.
gravatar-added
7. Select it and click Save changes.
That’s it. Your custom gravatar will be used whenever a commenter’s profile does not come with a gravatar.

No comments: