Software Engineering

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.

milan.latinovic

Senior PHP Engineer and Enterprise Architect at apilayer GmbH. Topics of interest: Software development, PHP, Java, Python, REST API, OpenApi, MySQL, Microservices, Integrations, Interfaces, Interoperability, Processes, Solution Architecture, LDAP, Azure

Recent Posts

Code Review Best Practices: Code reviewing and being reviewed

This article is about the code review best practices. It explains code review from the… Read More

1 year ago

What are the best Practices in REST API design

API design is an important aspect of modern software development. It allows different systems to… Read More

1 year ago

Next Industrial revolution: What is ChatGPT? Will it replace jobs?

This article sheds some light related to the question will ChatGPT or AIs in general… Read More

1 year ago

What is new in PHP 8.2: What are new features, what is deprecated?

This article provides an overview of new features and deprecations in PHP 8.2. PHP 8.0… Read More

1 year ago

Automation and AI in Software Engineering

This article is about Automation and Artificial Intelligence in Software Engineering: Experiences, Challenges, and Opportunities.… Read More

3 years ago

Enumerations in PHP 8.1 – with code example and references

PHP is getting more and more features. Enumerations in PHP are one of the latest… Read More

3 years ago