Pro Tip: Use the esc_attr Function to Format alt Tags When Using ACF
Intro
Originally this article recommended using the htmlentities function. However, after a lot of helpful feedback, I’ve learned it’s best practice to use esc_attr
If you’re rendering images with ACF, make sure you run the alt text against the htmlentities esc_attr function. Why? Because there’s a chance that the alt text could contain quotation marks "".
If it does, it will break the formatting of the alt tag as seen below.


