How To Fix Missing Gravatar Alt Tag Value In WordPress

We all know that having an ALT tag value for images is very important for SEO. If you run an SEO analysis on your website, you might have encountered the issue that the ALT tag value is missing from Gravatar images.

This issue is very common and can be fixed easily. So let’s learn How To Fix Missing Gravatar Alt Tag Value In WordPress in this article.

Before making any changes to any files, please take a full website backup ( Don’t depend on hosting providers’ backups)

What Is ALT Tag In Images?

The ALT tag value is for search engines to know what the image is all about. Like text content, Google can’t read pictures and check the content. What it can read is the ALT tag value.

For example, if you write “SEO coaching” as an ALT tag value for an image, then Google will understand that the image is all about SEO coaching and will show the image in the search results for that keyword.

One more benefit of adding an ALT tag value is that if the image can not be displayed for some reason, then the ALT tag value will be shown to the visitor instead of the image.

So your visitor will come to know that they have a missing image about that ALT tag value.

How To Fix Missing Gravatar Alt Tag Value In WordPress?

If you are using the default author profile, WordPress will fetch the author image from the Gravatar account if that exists with the same email ID that the author is using.

By default, Gravatar does not add any ALT tag value to images, although it is an SEO concern. On top of that, there is no direct way of adding an ALT tag value for gravatar images.

That is why you will see the ALT tag missing issue for gravatar images.

Fixing this issue is very easy if you have a basic knowledge of PHP and know how to access your website files and edit those.

It is always preferable to use a child theme and make those changes so that your changes will remain intact even if there are any theme updates.

As you can see below, I have a whole list of ALT tag missing issues, and all issues are due to the gravatar image.

Fix Missing Gravatar Alt Tag Value In WordPress

Although SEO tools like Ahrefs or Semrush do not show this as a serious concern, we should fix it as it could be a concern in ranking high in the google search result.

You need to head over to the function.php file located in the child theme directory and add the following piece of code.

What it does is that it adds an Alt tag value to the gravatar image. The alt tag value is “Profile Picture For XXX,” where XXX is the person’s name. In my case, it will be “Profile Picture For Rajib,” as I am writing the post.

/**
 * Gravatar Alt Fix
 * https://www.rianstech.com/review/fix-missing-gravatar-alt-tag-value/
 */
function gravatar_alt($text) {
    $alt = get_the_author_meta( 'display_name' );
    $text = str_replace('alt=\'\'', 'alt=\'Profile Picture For '.$alt.'\' title=\'Gravatar for '.$alt.'\'',$text);
    return $text;
}
add_filter('get_avatar','gravatar_alt');

Once you add these pieces of code, save the file, clear all cache, including the browser cache, and re-run the SEO analysis. The problem will be solved.

Conclusion: Fix Missing Gravatar Alt Tag Value

That’s all in this article. I hope now you can able to solve this problem. If you are still stuck with the issue and do not know how to proceed, do let me know in the comment section, and I will help you out.

Rajib
Rajib

Rajib Is The Founder Of RiansTech. A Seasonal Blogger And A Full-Time Product Designer For Over Two Decades. A Technology Freak And Loves To Write About It. RiansTech Is A Online Home For Him Where He Documents His Experiences And Learnings So That Others Can Get Benefited From It.

RiansTech
Logo