What Are Gravatars? How to Install Gravatars on WordPress Blogs

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:

<? php echo get_avatar ($ id_or_email, $ size = "96 & # 8242 ;, $ default =" <path_to_url> ');?>

  • $ 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:

    <? php wp_list_comments (array ('avatar_size' = ""> 55));?> Both functions checks with Gravatar.com if the email entered has an avatar associated with it and returns it if it does. Enabling Gravatar On Your WordPress Blog If your theme already supports Gravatar, all you need to do is click on the Discussion button under settings in the WordPress control panel, then scroll down and select the Show Avatars radio button in the Avatar Display section. You can also select the maximum rating of avatars you wish to display on your blog and a default avatar. The rating is chosen by the Gravatar registrant so it may not always be accurate.


Source by Christopher Mark Scott

Leave a Reply

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

Save & Share Cart
Your Shopping Cart will be saved and you'll be given a link. You, or anyone with the link, can use it to retrieve your Cart at any time.
Back Save & Share Cart
Your Shopping Cart will be saved with Product pictures and information, and Cart Totals. Then send it to yourself, or a friend, with a link to retrieve it at any time.
Your cart email sent successfully :)