How to Add ALT Text to Gravatar Images in GeneratePress?

Updated on

Do you want to add ALT text to Gravatar images in GeneratePress? If you are looking for a step-by-step tutorial, keep reading this article.

If you have been in the blogging and SEO field for a while, you know the importance of ALT tags for images. You can add ALT tags to normal media files when uploading or in the Gutenberg editor. But you cannot add ALT tags to Gravatar images in the usual way.

Since there are no methods available to add ALT text to Gravatar images directly via the WordPress admin area, we are going to use a bit of coding.

In this post, we will show you a quick method to add ALT text to your Gravatar images using a simple PHP snippet and the Code Snippets WordPress plugin.

Before proceeding with the tutorial, let’s take a moment to understand what a Gravatar image is and why adding ALT tags to them is crucial for your website’s SEO.

What Is Gravatar Image and Why You Should Add ALT Text to It

A Gravatar image is the avatar image or author thumbnail linked to your WordPress User profile. It shows up in the author box, post author box, and comments section on your WordPress website.

By default, these Gravatar images often load without proper ALT text or alt tags, which reduces search engine visibility and harms user experience for people with visual impairment.

Adding descriptive ALT text to your author images improves accessibility, strengthens search engine performance, and can boost results in tools like Google Lighthouse and Google Page Speed Insights.

Whether with a PHP snippet, the Code Snippets plugin, or by adding an alt attribute, ensure your post author content is both accessible and SEO-friendly.

How to Add ALT Text to Gravatar Images in GeneratePress Theme

How to Add ALT Text to Gravatar Images in GeneratePress
How to Add ALT Text to Gravatar Images in GeneratePress

You can add the ALT tags to your GeneratePress premium or free theme’s Gravatar in three simple steps:

  • Install the Code Snippet plugin/ edit the theme’s functions.php file
  • Paste the code mentioned in this post
  • Update the text based on your requirements.

Let’s take a look at the method in detail.

1. Installing Code Snippets Plugin

Step 1: Once you have logged in to your WordPress website, you need to go to the Add New Plugins section. You can either use the Code Snippets plugin or paste the snippet directly into your child theme’s functions.php file.

For this tutorial, we will use the Code Snippets method. So, install the plugin on your website.

Install Code Snippets Plugin
Install Code Snippets Plugin

Once you have completed the installation, activate it.

Activate Code Snippets Plugin - Add ALT Text to Gravatar Images in GeneratePress
Activate Code Snippets Plugin

After activation, you can move to the primary step in the tutorial.

2. Paste the PHP Snippet in Code Snippets

Step 2: You can see the plugin’s settings on the left-hand side of the admin area.

Code Snippets Settings - Add ALT Text to Gravatar Images in GeneratePress
Code Snippets Settings

Hit the Add New button and create a new snippet. You should also give it a descriptive name. The code you need to paste is:

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

3. Update the Code with Your ALT Tag

Step 3: If you take a closer look at the code, you can see a text saying ‘Gravatar for’. That is the ALT text. So, modify that part of the code according to your preferences if you need. But the default code is fine too.

Once you have modified the snippet with the new ALT tag, publish the snippet.

Code Snippet ALT Tag Code - Add ALT Text to Gravatar Images in GeneratePress
Code Snippet with ALT Tag

From now on, the Gravatar images will contain the author’s name in the ALT text.

That’s it!

This is how you can add ALT text to Gravatar images in GeneratePress.

Frequently Asked Questions

Now, let’s see some of the frequently asked questions and answers regarding this topic.

Do I need GP Premium to add ALT text to Gravatar images in GeneratePress?

No, you can add ALT text using a simple PHP code snippet and the Code Snippets plugin. However, GP Premium offers more flexibility for customizing your author box and block elements, which can improve design and search visibility.

Can I use GenerateBlocks Pro or Elementor to build a custom author box with ALT text?

Yes, with GenerateBlocks Pro or even Elementor Pro, you can create a custom author box. Inside the Block Settings, you can add an author image, assign a custom class, and apply Dynamic tags to ensure ALT attributes are included.

Will adding ALT text to Gravatar images help with Google Analytics or SEO tools like META SEO Inspector?

Yes. Proper ALT text improves search engine visibility, which you can monitor with Google Analytics or extensions like META SEO Inspector. Search engines use these attributes for better indexing of author archives and single posts.

What if I want to load author images faster with Lazy Load?

You can use plugins like A3 Lazy Load or caching solutions such as FlyingPress or WP Rocket. These methods make Gravatar images and author thumbnails load faster. This reduces page speed problems and improves user experience.

How does adding ALT text affect responsive design and user experience?

ALT text improves accessibility for users with visual impairment while keeping a responsive design intact. By combining proper global styles, style builder inputs, and block inserter options, you ensure that every author bio and post meta section enhances user interaction.

Can adding ALT text conflict with other plugins like ACF Pro?

Nope. Adding ALT text to the GeneratePress theme using WordPress filters won’t cause any compatibility issues.

How Adding ALT Text Boosts SEO in GeneratePress

Adding ALT text to your Gravatar images in the GeneratePress theme is a small but strong step. It helps your site show up better in search engines.

By using a simple PHP snippet, you ensure that every author image, author bio, and custom author box is both accessible and SEO-friendly.

We highly recommend doing this on your GeneratePress-powered website.

So would you add ALT text to your Gravatar images?

Let us know in the comments.

Photo of author
Sreehari P Raju
Disclaimer: Affiliate links of some product(s) are being used on this page, if you follow the link and make a purchase, we may receive compensation from respective companies. This compensation comes at no additional cost to you.

Leave a Comment

Your email address and website details will not be published. Required fields are marked with *.