Site logo

Archived topic

Alt Text on Comments

3 replies · Started by cgarrett08 on April 28, 2022

Viewing posts 1–4 of 4

I am wanting to add alt text to blank avatars of people who leave comments. The software that I am using to help with SEO, says this is a huge impact on my site.

This solution worked for anyone else needing the info.

Copy and paste into functions.php Don't do this if you don't know what you are doing.

/**
* Gravatar Alt Fix
* https://wphelper.site/fix-missing-gravatar-alt-tag-value/
*/
function gravatar_alt($text) {
$alt = get_the_author_meta( 'display_name' );
$text = str_replace('alt=\'\'', 'alt=\'Avatar for '.$alt.'\' title=\'Gravatar for '.$alt.'\'',$text);
return $text;
}
add_filter('get_avatar','gravatar_alt');

Thank you for sharing! Glad you found a solution! Feel free to reach out anytime you’ll need assistance with anything else. :)

This archived topic is closed to new replies.