-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Description
Block gallery image markup has included a data-id attribute on each gallery image <img> tag since WordPress 5.0. This attribute includes the image attachment post object's id for images hosted locally in the media library. It allows plugins and themes to access other structured data related to the image through the core attachment post type. This can be used in both PHP and JS to pre- or post-process the post content markup.
The data-id attribute is currently missing from the refactored gallery block (as of Gutenberg 11.7.1). Now that all gallery images are image blocks, this attribute should be provided for all locally-hosted images in the content. Adding the attribute to more images is much less likely to cause breakage than removing it from existing markup and on new gallery posts; in fact, it would probably resolve issues with current extender usage of this markup. In my usage, removing the attribute breaks several themes/plugin/sites that I maintain.
This was previously fixed here: #30710, but appears to have been reverted. I can't find any discussion of why it was reverted. This is the only remaining blocking issue that I see for including the gallery refactor in core.
A possible backup plan would be to instead fix support for the core get_post_galleries() function that has been broken since WordPress 5.0. That would allow some programmatic relationship between images in the content and their associated attachment post objects. However, that would still be a break in backwards compatibility and require theme/plugin changes.
Step-by-step reproduction instructions
- Create an image gallery in WordPress 5.8 with images uploaded to the media library.
- Observe that the published gallery markup includes a
data-idattribute on the gallery<img>tags. - Enable the gallery refactor experiment with Gutenberg 11.7 and create another image gallery with images uploaded to the media library.
- Observe that the published gallery markup does not include the
data-idattribute on the gallery<img>tags. - An example of the resulting breakage can be seen with the Arbutus theme. Using the
gallerypost format, the front page excerpt view should display a partial gallery with the first several images from in the post content. This doesn't work with the refactored gallery block - a blank bar displays instead.
Screenshots, screen recording, code snippet
This was previously fixed with the code here: a2253ec
Environment info
Testing with WordPress 5.9-alpha and Gutenberg 11.7.1 with the gallery block refactor experiment enabled.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes