graffiti 3405959 1920

ALT and TITLE tag for WordPress, Gravatars, improve SEO

ALT and TITLE tag for WordPress are very important in terms of Search Engine Optimization (SEO). Basic SEO rule suggests to add ALT and TITLE tags to all of your images.

This is quite straight forward for most of the images on your site. In example, most of the images can be found inside Dashboard, within Media section of your WordPress back office.

However, Gravatars are somewhat specific because they are taken from the external sources.

Configure ALT and TITLE tag for WordPress, Gravatars

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.