So I use an app within HubSpot called Page Grader, and now that I’m back to the business of posting blog posts, I’ve noticed I’ve made a little error in my WordPress template. Page Grader looks at the various pages of your site and lets you know if it sees anything that should be fixed. Common errors are forgetting to put unique page names, no meta tags and lack of alt tags on some images. All of these add up to on-page SEO, which can really make or break a page’s ranking in Google’s eye. This includes blog posts, because they’re web site pages, too.
On my latest posts I’ve gotten a few comments (thanks Jody and Linda!) and now Page Grader is pissed because their little images (and mine, for that matter) don’t have alt tags. While normally it’s not a big deal, I did want to do something about that.
Like many customers I talk to on a daily basis, I want all pages to have green checkmarks:
Keep in mind it’s not something that everyone can do; if you use an e-comm site, they add some random images you just can’t put alt tags on. This one, though, I do have control over.
The images in the comments are called Gravatars, and are pulled from someone’s account here: http://en.gravatar.com/
It took me awhile to find where the code was that pulled in Gravatars in WordPress, but I did find it it wp-includes/pluggable.php. The code is:
if ( !function_exists( ‘get_avatar’ ) ) :
/**
* Retrieve the avatar for a user who provided a user ID or email address.
*
* @since 2.5
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternate text to use in image tag. Defaults to blank * @return string <img> tag for the user’s avatar
*/
function get_avatar( $id_or_email, $size = ’96′, $default = ”, $alt = ” ) {
if ( ! get_option(‘show_avatars’) )
return false;
if ( false === $alt)
$safe_alt = ”;
else
$safe_alt = esc_attr( $alt );
if ( !is_numeric($size) )
$size = ’96′;
etc.
Now, my original idea was that I wanted the ALT tag to be dynamically created, and uses the author’s name. I tried adding <?php echo esc_attr($comment_author); ?> to $alt = ”, but that didn’t work, as whatever is within ” will just show as plain text. I then settled for adding Redd-Design comment as the alt tag.
Ideally I’d like to have each image have a unique ALT tag, but after much scraping the web, I couldn’t find a good reference to it. Anyone have other ideas?
Thanks for reading this article, if you have questions, comments or concerns, we'd love to hear them, so comment below!
And as always, make sure you're following us on Twitter and Facebook!


Recent Comments