Last active
June 20, 2024 09:01
-
-
Save gmmedia/01c040966da670a707f2845fb34413e4 to your computer and use it in GitHub Desktop.
Add alt tag to WordPress Gravatar images
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
<?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ü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
Hi, I added this code to code snippets, but it doesn't seem to work? Should I add it to the root file instead? Thanks