Image Element inside Query Loop does not output media library alt text

8

Hi,

there is an issue with the Image Element when it is used inside a Query Loop.

  • When the Image Element is placed on a regular page, it correctly outputs the image’s alt text from the WordPress Media Library.
  • When the same Image Element is used inside a Query Loop, the rendered <img> element has an empty or missing alt attribute, even though the image has a valid alt text assigned in the Media Library.

This causes accessibility issues and is reported by tools such as Lighthouse.

Is this a bug or is there a setting required to preserve the media library alt text inside Query Loops?

lothar.koch@gmail.com

Replies

Responses

  1. Hi. Image Element inside Loop is working as Dynamic Image (you fetch thumbnail dynamically and not image as Media library). Alt is became also dynamic field and you can put post title there (recommended) or any other dynamic data

  2. Okay, that could be a workaround. However, it would be better if the alt text were used automatically, since that is the text users assign to the image in the media library. It’s also the text they expect to be displayed, given that it appears when the image is embedded normally. 🧐Thanks anyway, and all the best.

    1. it’s already automatic but in block Dynamic Image

  3. I use Greenlight, here I only see the “Image Block”. Unfortunately there is no “Dynamic Image” block here. 🤷‍♂️

    1. yes, it’s part only for Greenshift Query. For GreenLight you need to set dynamic field for alt. You can use dynamic placeholder there

  4. Yes, I used the {{POST_TITLE}} placeholder here.There probably isn’t one for the alt text, though, because that would be part of the media library item, right?

    1. yes. Currently there is no easy way to get it. It requires to loop over media attachments

  5. Okay, thanks for the info. Maybe you’ll be able to incorporate it at some point.Thanks.