Skip to content

Instantly share code, notes, and snippets.

@henshaw
Created July 18, 2021 15:54
Show Gist options
  • Select an option

  • Save henshaw/dbb966bbc916a5c4e2426f5367cfe0a8 to your computer and use it in GitHub Desktop.

Select an option

Save henshaw/dbb966bbc916a5c4e2426f5367cfe0a8 to your computer and use it in GitHub Desktop.
Add ALT attribute with author name to Gravatar image in WordPress – Copy to functions.php
// Adds ALT attribute with author name to Gravatar image in WordPress
function replace_content($text)
{
$alt = get_the_author_meta( 'display_name' );
$text = str_replace('alt=\'\'', 'alt=\''.$alt.'\'',$text);
return $text;
}
add_filter('get_avatar','replace_content');
@henshaw
Copy link
Copy Markdown
Author

henshaw commented Jul 18, 2021

Used in conjunction with get_avatar when displaying an author's image on WordPress

<?php echo get_avatar( get_the_author_meta( 'ID' ), 120); ?>

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