WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 months ago

#33979 assigned enhancement

Add filter for 'post_gallery_item'

Reported by: lostmotionassembly Owned by: antpb
Milestone: 5.0 Priority: normal
Severity: normal Version: 4.4
Component: Gallery Keywords: has-patch
Focuses: Cc:

Description

This would allow developers to customise the individual gallery items, without having to duplicate the entire gallery_shortcode() function to do so. This would make it quicker, easier to understand, and reduce the likelihood of the gallery shortcode functionality 'drifting' away from core. A sample use case would be wanting to add additional classes to the gallery item based on attachment meta (such as additional orientation options like 'square' or 'panorama').

Attachments (3)

33979.diff (894 bytes) - added by mauteri 3 years ago.
Added filter for gallery item classes.
33979-2.diff (908 bytes) - added by antpb 5 months ago.
33979-3.diff (906 bytes) - added by antpb 5 months ago.

Download all attachments as: .zip

Change History (14)

#1 @wonderboymusic
3 years ago

  • Keywords needs-patch added

@mauteri
3 years ago

Added filter for gallery item classes.

#2 @mauteri
3 years ago

  • Keywords has-patch added; needs-patch removed

#3 @antpb
5 months ago

  • Milestone changed from Awaiting Review to 4.9.3

I've refreshed the patch for 4.9.3. This could be very useful going forward.

@antpb
5 months ago

#4 @SergeyBiryukov
5 months ago

  • Milestone changed from 4.9.3 to 5.0

New hooks are generally added in major releases, moving to 5.0.

#5 @antpb
5 months ago

No prob! I've attached a new patch with the proper version in the docs.

@antpb
5 months ago

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


4 months ago

#8 in reply to: ↑ 6 @desrosj
4 months ago

Replying to tristangemus:

Similar? https://core.trac.wordpress.org/attachment/ticket/38228/patch_38228.3.diff

This is similar but a different context. That ticket aims to filter the entire generated output of the shortcode whereas this one is being used for just a single image within the gallery. Love both of these tickets, but we should definitely keep them separate :)

I would also like to see the ability to modify more than just classes using a filter. Adding data attributes to the tag, or changing the image size for the current image would be great. That could allow more creative gallery layouts, such as the tiled gallery in Jetpack. https://jetpackme.files.wordpress.com/2013/11/example-gallery-tiled.jpg

Last edited 4 months ago by desrosj (previous) (diff)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


3 months ago

#10 @antpb
3 months ago

  • Owner set to antpb
  • Status changed from new to assigned

It was mentioned by @mikeschroder in the Media Component meeting today that we should look into how this may impact Gutenberg. My gut tells me that this wont enhance the Gutenberg experience since the filter is set somewhere in the shortcode functions but maybe we can look into this through the Gutenberg lens.

Note: See TracTickets for help on using tickets.