Gravatar avatars are small images that represent an email address. Their purpose is to allow for global recognition of commenters and persons on the Internet. Rather than having a different avatar for different sites, people can register an avatar at Gravatar.com and associate it with their own unique email address.
Blog posts in WordPress that have commenting enabled typically require an email address to submit a comment. Once a comment has been submitted with the email field filled in, WordPress sends the email address as a data string to Gravatar.com; if Gravatar.com has an avatar for that email address, the avatar will be used. Often times Gravatar.com does not have an avatar associated with an email address, in which case a default avatar is used.
The Difference Between Avatars and Gravatars
Avatars are images that represent a person on the Internet. Many times forums and other types of online communities will allow users to upload a small image that represents them on a site. Gravatar is the name of the service which allows people to register an avatar in association with an email address. However, an avatar generated from Gravatar.com is sometimes referred to as Gravitar (which is also the name of the service).
How to Setup Gravatar on a WordPress Blog
The WordPress development team created two easy-to-use PHP functions for theme designers who want Gravatar support in their themes.
Gravatar Support in the get_avatar Function
The get_avatar function is as follows:
- $ id_or_email represents the comment author ID or email. You must substitute this with $ comment for the function to work. For WordPress 2.7 and lower, the official WP support page indicates that you need to use get_the_author_id () instead. The page also indicates that you should use get_the_author_meta ('user_email') for WordPress 2.8. I have found that function to be dysfunctional so I would recommend using $ comment if the get_the_author_meta function does not work.
- $ size represents the size in pixels of the avatar displayed (max is 512).
<path_to_url>should be replaced with the URL of a default avatar image should you wish to use one. If you are just looking to install Gravatar on an already put-together WordPress theme, all you need to do is replace the chunk of code that creates avatars in your comment.php file with the get_avatar function (above). </ path_to_url>
Gravatar Support in the wp_lists_comments Function The popular wp_list_comments template tag also has Gravatar support built-in. Instead of only retrieving an avatar from Gravatar.com (or just displaying a default avatar), the wp_list_comments template tag lists comments (content, author, URL included) and features additional parameters that allow for further customization. To set the avatar size with wp_list_comments (which is the only parameter the function has related to Gravatar), simply set the get_avatar string key in the $ args array to whatever integer you want. Example:
Source by Christopher Mark Scott