Skip to content

Instantly share code, notes, and snippets.

@henshaw
Last active September 3, 2023 01:31
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 henshaw/bdd9a420cb33184b00cb0b27c9eda155 to your computer and use it in GitHub Desktop.
Save henshaw/bdd9a420cb33184b00cb0b27c9eda155 to your computer and use it in GitHub Desktop.
Add ALT text to gravatar image in byline
// If you use this Gravatar code in your WordPress templates
<?php echo get_avatar( get_the_author_meta( 'ID' ), 60); ?>
// Add this to functions.php to include ALT text with the image
function gravatar_alt($text) {
$alt = get_the_author_meta( 'display_name' );
$text = str_replace('alt=\'\'', 'alt=\'Headshot for '.$alt.'\'',$text);
return $text;
}
add_filter('get_avatar','gravatar_alt');
@henshaw
Copy link
Author

henshaw commented Sep 3, 2023

Add this code to the functions.php file to include ALT text with gravatar images. This is a slightly modified version of the code found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment