Alt-TagsAfter looking at several WordPress websites ‘alt tags’, I noticed that even though we had gone through the entire site and added alt tags when they were missing and placing keywords within our alt tags, I notice a common problem.  The alt tags were missing from most of the image sliders, even though we had added them in the ‘Media Library’.

With many of these plugin’s, they don’t take the time to add the alt tag into the coding for SEO purposes.

I thought I would cover how we fixed one site that was using Custom Fields with an ACF (Advanced Custom Fields) :Repeater Field that we had inherited from a different designer.  The repeater was on the front page and the original coding looked like this:

<?php get_the_image( array( ‘meta_key’ => ‘Feature’, ‘image_class’ => ‘border’, ‘size’ => ‘full’, ‘width’ => ‘930’, ‘link_to_post’ => false ) ); ?>
<div id=”homeRotator”>
<?php $values = array();
while(the_repeater_field(‘rotator_images’)):
$values[] = get_sub_field(‘rotator_image’);
endwhile;
shuffle($values);
foreach ($values as $value) :
$size = “full”;
$image = wp_get_attachment_image_src($value,$size); ?>
<img src=”<?php echo $image[0]; ?>” />
<?php endforeach; ?>
</div>

Notice that the img src was echoed but there was no echo for the an alt tag.  Here’s the final code that fixed the issue.

 

<?php get_the_image( array( ‘meta_key’ => ‘Feature’, ‘image_class’ => ‘border’, ‘size’ => ‘full’, ‘width’ => ‘930’, ‘link_to_post’ => false ) ); ?>
<div id=”homeRotator”>
<?php $values = array();
while(the_repeater_field(‘rotator_images’)):
$values[] = get_sub_field(‘rotator_image’);

endwhile;
shuffle($values);
foreach ($values as $value) :
$alt = get_post_meta($value, ‘_wp_attachment_image_alt’, true);
$size = “full”;
$image = wp_get_attachment_image_src($value,$size); ?>

<img src=”<?php echo $image[0]; ?>” alt=”<?php echo $alt; ?>” />
<?php endforeach; ?>
</div>

2 lines were added to get the results.  I first called the variable for the alt tag so it would call the correct tag with the image through the $value variable.  Next I echoed the variable after the image.

Leave a Reply

Your email address will not be published. Required fields are marked *