Last active
September 3, 2023 01:31
-
-
Save henshaw/bdd9a420cb33184b00cb0b27c9eda155 to your computer and use it in GitHub Desktop.
Add ALT text to gravatar image in byline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.