Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gmmedia
Last active March 11, 2023 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmmedia/01c040966da670a707f2845fb34413e4 to your computer and use it in GitHub Desktop.
Save gmmedia/01c040966da670a707f2845fb34413e4 to your computer and use it in GitHub Desktop.
Add alt tag to WordPress Gravatar images
<?php
// Add alt tag to WordPress Gravatar images
// Full how-to: https://bloggerpilot.com/gravatar-alt-tag/
function bloggerpilot_gravatar_alt($bloggerpilotGravatar) {
if (have_comments()) {
$alt = get_comment_author();
}
else {
$alt = get_the_author_meta('display_name');
}
$bloggerpilotGravatar = str_replace('alt=\'\'', 'alt=\'Avatar f&uuml;r ' . $alt . '\'', $bloggerpilotGravatar);
return $bloggerpilotGravatar;
}
add_filter('get_avatar', 'bloggerpilot_gravatar_alt');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment