I have been doing quite a few changes to Crunchify site recently related to Search Engine Optimization (SEO) and better site loading prospective.
While working with my client
last week, we discover that Bing SEO Report
showed quite a few SEO suggestions.
If you are wondering what all types of suggestions
Bing is giving then look at below:
- The title is missing in the head section of the page.
- The <img> tag does not have an ALT attribute defined.
- The page contains multiple titles.
- Evaluated size of HTML is estimated to be over 125 KB and risks not being fully cached.
- The page is missing meta language information.
- The title is too short or too long.
- The <h1> tag is missing.
- The description is missing in the head section of the page.
- The description is too long or too short.
In this tutorial we are going to discuss how to fix
<img> tag ALT attribute issue
.
ALT & TITLE tags for Gravatar Tips 🙂
Let’s get started:
Step-1.
- Go to Bing Webmaster tool.
- I assume that you have already
added
your site andverified
it. - Click on Dashboard -> Reports & Data ->
SEO Reports
.
Step-2
- Click on
The <img> tag does not have an ALT attribute defined
link.
Step-3
- Click on any one of the
NON-COMPLIANT PAGES.
- Wait for your report to load.
- Don’t click
Analyze
button now. - Click on
Page Source
Tab.
Step-4
- You could see error in
yellow color
background as you see at the top of this page.
Step-5 Why this error?
In WordPress, by default, Gravatar doesn’t add ALT tag while grabbing image from gravatar server. Optimizing a site for SEO and overall html5 compliance
requires that you have ALT
and preferably TITLE
tags for all images displayed on the site and hence Bing is showing that error.
If you have default WordPress comment, you would miss ALT tag for all your commenter’s image and that’s a big issue.
Step-6 How to fix this?
We could simply fix missing ALT and TITLE tag value by adding below code to your theme’s functions.php file.
function crunchify_gravatar_alt($crunchifyGravatar) { if (have_comments()) { $alt = get_comment_author(); } else { $alt = get_the_author_meta('display_name'); } $crunchifyGravatar = str_replace('alt=\'\'', 'alt=\'Avatar for ' . $alt . '\' title=\'Gravatar for ' . $alt . '\'', $crunchifyGravatar); return $crunchifyGravatar; } add_filter('get_avatar', 'crunchify_gravatar_alt');
Step-7 How to verify?
- Now clear your site cache if you are using WP Super Cache or W3 Total Cache plugin.
- Reload your page.
Right click
on gravatar andInspect
HTML element.- You should see
ALT and TITLE
both tag values populated correctly.
- Now go to Bing Webmaster tool and click on
Analyze
button. - You shouldn’t see any error message now.