Related: #14130, #20230.
I am currently trying to use a lightbox plugin on a gallery, but it needs to insert an extra attribute onto the image links.
gallery_shortcode()
calls wp_get_attachment_link()
, so you can use the wp_get_attachment_link filter.
I can understand why the "post_gallery" filter is called so soon, for devs who want to completely replace the functionality of this shortcode.
You can actually change the output of the shortcode using that filter without completely replacing the functionality:
function filter_gallery_shortcode_output_29832( $gallery, $attr ) {
remove_filter( 'post_gallery', __FUNCTION__, 10, 2 );
$gallery = gallery_shortcode( $attr );
add_filter( 'post_gallery', __FUNCTION__, 10, 2 );
// Change the output
// $gallery = ...
return $gallery;
}
add_filter( 'post_gallery', 'filter_gallery_shortcode_output_29832', 10, 2 );