WordPress Gravatar ALT tag error fixing for SEO

To fix alt tag missing shown on SEO report for Gravatar image we can simply add the following code on functions.php file.

function wp_gravatar_alt($wpGravatar) {
    if (have_comments()) {
        $alt = get_comment_author();
    }
    else {
        $alt = get_the_author_meta('display_name');
    }
    $wpGravatar = str_replace('alt=\'\'', 'alt=\'Avatar for ' . $alt . '\' title=\'Gravatar for ' . $alt . '\'', $wpGravatar);
    return $wpGravatar;
}
add_filter('get_avatar', 'wp_gravatar_alt');
Source : https://crunchify.com/are-you-missing-wordpress-gravatar-alt-value-how-to-fix-tag-does-not-have-an-alt-attribute-defined-seo-error/

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.