graffiti 3405959 1920

ALT and TITLE tag for Gravatars, improve WordPress SEO

Having problems with ALT and TITLE tag for Gravatars and search engine optimization on your web site? Your checker is failing on ALT and TITLE tag for Gravatars on your web site.

Use this code snippet and resolve ALT and TITLE tag for Gravatars issues.

/* * This is function that adds ALT and TITLE for gravatars * It's very important in terms of SEO compliance. */ 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');


What is happening in this code snippet?

Actually it is very simple.

We are creating a WordPress hook on ‘get_avatar’ action.

This hook is calling a replace_content function.

Furthermore, function replace_content is setting up alt tag with author name and setting up a title tag with gravatar name of the author.

Finally, this will solve your ALT and TITLE tag for Gravatars issues.

If you are interested in additional optimization of WordPress, learn more about optimizing WordPress database.

Furthermore, check out the right way of promoting web sites in WordPress.

Finally, if you like these posts, don’t be a stranger! Comment, share, subscribe and become part of our community.

Details on how to use gravatars with WordPress can be found here.