Have you ever commented on a blog post and wondered what the icon next to your name is? You don’t need to guess anymore. It is a gravatar. In this article we are going to explain what a gravatar is and why you should use it.
What is a gravatar?
The name gravatar is derived from the word avatar. An avatar is the graphical representation of a person through which their persona is reflected. Gravatar basically means Globally Recognized Avatar. The word global is used because gravatars are not just limited to a website or platform, they are used by millions of people and websites around the world.
How gravatar works
WordPress supports Gravatar by default. So, whenever someone leaves a comment on a blog post using their email, the gravatar servers fetch the picture associated with their profile and display it beside their name. This allows everyone to build a global identity across different websites and platforms.
Changing the default gravatar images in your WordPress website
You can change how the gravatar looks for everyone on your website who doesn’t have a custom gravatar image set for their profile. Below are steps to change the gravatar.
- Visit Settings -> Discussion from your admin dashboard.
- Under the Default Avatar section you can select a gravatar icon that you prefer.
- Once done save the changes.
You can also add a custom gravatar picture for your website. Follow the below steps for it.
- The gravatar image that you will use needs to be 250 x 250 pixels in size and square.
- Once the image is created visit Media -> Add New from your admin dashboard.
- Upload the image that you want to use and copy the File URL.
- Now in your WordPress theme editor edit the functions.php file and add the below code to it.
add_filter( 'avatar_defaults', 'custom_gravatar' ); function custom_gravatar ($avatar_defaults) { $avatar = 'http://website.com/wp-content/uploads/2020/11/custom-gravatar.png'; $avatar_defaults[$avatar] = "Custom Gravatar"; return $avatar_defaults; }
Replace the $avatar variable value with the File URL that we copied earlier.
- Now you can visit Settings -> Discussion and find the new custom avatar in the list of Default Avatar. Select it and save the changes.
- Now anyone who doesn’t have a custom gravatar set in their profile will be using the new custom avatar whenever they comment on your blog post.