Archived topic
Alt Text on Comments
3 replies · Started by cgarrett08 on April 28, 2022
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.
Hi there,
GeneratePress has no control over this.
To add an alt text to Author images, you may try the PHP snippet mentioned here: https://bloggerpilot.com/en/gravatar-alt-tag/
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Adding it through Code Snippets should work.
If the first code doesn’t work, try this as well: https://wphelper.site/fix-missing-gravatar-alt-tag-value/
Hope this helps! :)
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. :)