Milan Latinović
Software Engineer and Enterprise Architect
ALT and TITLE tags for WordPress, Gravatars, improve SEO
This article will introduce you to a simple way to add ALT and TITLE tags for Gravatars to your WordPress sites. This will help you to make your site a bit more search engine optimized.
Table of Contents
ALT and TITLE tags
ALT and TITLE tags for WordPress are very important in terms of Search Engine Optimization (SEO). The Basic SEO rule suggests adding ALT and TITLE tags to all of your images.
This is quite straight forward for most of the images on your site. For example, we find most of the images inside the Dashboard, within the Media section of your WordPress back office.
What is Gravatar?
Firstly, let us understand what is Avatar? Avatar is a graphical representation of a user, which can be picture, some random animation or really anything that user finds appropriate.
Gravatar means Globaly Recognizable Avatar, which is associated with user’s email. When user leaves a comment on your web site, a Gravatar will appear.
However, Gravatars are somewhat specific because they are taken from external sources. Meaning, picture will appear but this picture will not have any ALT or TITLE tags. Finally, this will result in your SEO checker failing for ALT and TITLE tags for WordPress Gravatars.
Configure ALT and TITLE tags for WordPress, Gravatars
Having problems with ALT and TITLE tags 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 a 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');
Then, understand 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.
Details on how to use gravatars with WordPress can be found here.