How to Fix Missing Gravatar Alt Tag Value in WordPress? Easy Guide

Fix Missing Gravatar Alt Tag Value in WordPress: If you’ve done an SEO audit on your WordPress website, you might have found that you’re getting some alert for missing alt tags in your gravatar author photo. This is an increasingly common issue, and I am optimistic that in a forthcoming update WordPress will fix it. Before then, I have created this short guide to show you to have a simple function this will add alt tags to your Gravatars.

This guide is really simple, but you need to know PHP and do not have to do anything, just copy it and paste it. I suggest you to copy and paste the following code into the functions.php child theme, or you can use a plugin or WordPress code snippets.

The Function To Add Alt Tags To Gravatar Images

This is the function you would use to connect the gravatar picture. In this case, the alt tag would be “This is Irfan” because my name is ‘Irfan.’ The feature uses the Gravatar user’s screen name to apply a related alt-tag to the Gravatar.

/**
* Gravatar Alt Fix
*/
function simplyirfan_gravatar_alt($text) {
$alt = get_the_author_meta( 'display_name' );
$text = str_replace('alt=\'\'', 'alt=\'This is '.$alt.'\' title=\'This is '.$alt.'\'',$text);
return $text;
}
add_filter('get_avatar','simplyirfan_gravatar_alt');
Fix Missing Gravatar Alt Tag Value in WordPress

Also READ,

Leave a Comment