Fix Missing Gravatar Alt Tag Value In WordPress

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 come across this 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.

Disclaimer: Before making any changes to any files, please take a full website backup ( Don’t depend on hosting providers’ backups). You can use the Duplicator plugin to take a full backup. This trick is tested in Astra and GeneratePress and there is no issue. However, we can not guarantee that this code will work for other themes or not.

Table Of Contents

What is image alt tag value?

An ALT tag value is for search engines to know what the image is all about so that search engines can read images properly. Search engines can not know what contents you have in images. 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, then the ALT tag value will be shown 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. No 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 very easy if you have 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. 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.

Fix Missing Gravatar Alt Tag Value In WordPress

You need to head over to the function.php file located under 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 the XXX is the person’s whole gravatar image. In my case, it will be “Profile Picture For Rajib,” as I am the one writing or commenting here.

/**
 * 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 rerun 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 fairly simple problem. If you are still stuck with the issue and did not know how to proceed, do let me know in the comment section, and I will help you out.

You may also like to read:
1. How to control Heartbeat API in WordPress
2. How to control WordPress Cron

Leave a Comment

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

two × 3 =

Scroll to Top
Copy link
Powered by Social Snap