How to add a “Alt” and “Title” for the Author Gravatar Icon in the blog page

If you want to add a alt text for the Author Gravatar Icon then kindly follow the below steps.

Step 1

Open the file in this path /wp-content/themes/theme-folder/functions.php using some editor like DreamWeaver and scroll to the end of the file then append the below code,

Note : If you have used the child theme then get into the file path /wp-content/themes/childtheme-folder/functions.php.

function replace_content($text)
{
$alt = get_the_author_meta( 'display_name' );
$text = str_replace('alt=\'\'', 'alt=\'Avatar for '.$alt.'\' title=\'Gravatar for '.$alt.'\'',$text);
return $text;
}
add_filter('get_avatar','replace_content');

Rate This Article

(0 out of 2 people found this article helpful)

Leave A Comment?

This site uses Akismet to reduce spam. Learn how your comment data is processed.