WordPress uses Gravatar for commenter avatars — this is common knowledge. But have you noticed that Gravatar avatars have an empty Alt attribute? This clearly doesn’t comply with W3C standards. Here’s a method to set the alt attribute for WordPress Gravatar avatars.
Edit the wp-includes/pluggable.php file in your site’s root directory and search for the get_avatar function.
function get_avatar($id_or_email, $size = '96', $default = '', $alt = false) {
// If avatar display is not enabled, return false
if (!get_option('show_avatars'))
return false;
// If $alt is false, set $safe_alt to empty string; otherwise escape and set $safe_alt
if (false === $alt)
$safe_alt = '';
else
$safe_alt = esc_attr($alt);
}
Replace it with the following code:
function get_avatar($id_or_email, $size = '96', $default = '', $alt = false) {
// If avatar display is not enabled, return false
if (!get_option('show_avatars'))
return false;
// If $alt is false, set $safe_alt to "Gravatar"
if (false === $alt)
$safe_alt = 'Gravatar'; // Alt attribute set to "Gravatar"
// $safe_alt = get_comment_author($alt); // Some say this outputs the username; in testing, alt shows "Anonymous"
else
$safe_alt = esc_attr($alt); // Escape and set $safe_alt
}
And there you have it — your WordPress Gravatar avatars now have proper alt attributes.