About design and nearby

How to use ALT tags with Advanced Custom Fields plugin

Posted: August 19th, 2019 | Author: | Filed under: Development, Tips and Tricks | Tags: , , , | No Comments »

If you work with Advanced Custom Fields (ACF) plugin for WordPress, probably, you faced the same problem as I did: alt tags for images. The idea is clear – you want to upload and select an image as you do it usually with native WordPress media popup and get the alt tag value for this image filled in also.

The code could be kinda

  1. <img src="<?php echo $grey_section['image']['url']; ?>" alt="" />

And.. how to attach image alt?

Here is the solution:

  1. <img src="<?php echo $grey_section['image']['url']; ?>" alt="<?php echo $grey_section['image']['alt']; ?>" />

And the trick is to set ‘Image array’ to Image Object:

Image showing how to set alt tag

*You can always use var_dump($image); to print out the $image variable to know what is inside $image.

Happy coding!

Share Button

Check Related Posts:

Leave a Reply

  • 9 − two =

Looking for a Freelance UX & UI designer for your project? I’m ready to jump onboard!

Let's discuss your project now