Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#41853 closed feature request (worksforme)

Filter to handle/override the list of IDs in the Gallery Shortcode

Reported by: TigrouMeow Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8.1
Component: Gallery Keywords:
Focuses: ui Cc:


It would be nice to handle the IDs of the media which are used in the Gallery Shortcode from other plugins, depending on the attributes of the shortcode for instance.

A simple filter like:

$attr['ids'] = apply_filters( 'gallery_images', !empty( $attr['ids'] ) ? $attr['ids'] : null, $attr );

Would be perfect! And it could be right before:

if ( ! empty( $attr['ids'] ) ) {
  // 'ids' is explicitly ordered, unless you specify otherwise.
  if ( empty( $attr['orderby'] ) ) {
                $attr['orderby'] = 'post__in';
  $attr['include'] = $attr['ids'];

It is a simple change that wouldn't break anything. And it would allow plugins/themes to handle images in Gallery without having to create complicated Gallery systems. What about it?

Thanks :)

Change History (3)

#1 @birgire
4 years ago

Thanks for your suggestion, but what about the shortcode_atts_gallery filter available since version 3.6?


add_filter('shortcode_atts_gallery', function( $out, $pairs, $atts ) {
    // ... 
    return $out;
}, 10, 3 );
Version 0, edited 4 years ago by birgire (next)

#2 @TigrouMeow
4 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Indeed, that works perfectly for me, in my case :) I'll mark this as resolved. Thanks a lot for your help, I didn't knew about this filter :)

#3 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.