[wp-trac] [WordPress Trac] #29832: Add filter to final output of gallery_shortcode
WordPress Trac
noreply at wordpress.org
Thu Oct 2 13:33:16 UTC 2014
#29832: Add filter to final output of gallery_shortcode
-------------------------+------------------------------
Reporter: dcrabill | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Gallery | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses: template
-------------------------+------------------------------
Old description:
> This is similar to [#26623] but a lot simpler.
>
> The attached patch adds a "gallery_content" filter to the end of the
> gallery shortcode.
>
> It would be nice if the gallery shortcode had an available filter at the
> end, before the shortcode output was returned. This would be similar to
> the "the_content" filter, but just for a gallery.
>
> I am currently trying to use a [https://wordpress.org/plugins/blueimp-
> lightbox/ lightbox plugin] on a gallery, but it needs to insert an extra
> attribute onto the image links. It currently utilizes the "the_content"
> filter and works well on galleries added to the main content of a post.
>
> However, I am trying run the gallery shortcode outside the main content,
> so the plugin doesn't work. As far as I can tell, the plugin author
> doesn't have a way to get his lightbox to work on galleries added outside
> the main content or excerpt.
>
> I can understand why the "post_gallery" filter is called so soon, for
> devs who want to completely replace the functionality of this shortcode.
> I don't want to replace it, nor do I want the lightbox plugin to replace
> it... I want to use the standard Wordpress gallery, but with that
> particular lightbox functionality added to it. This patch would allow
> that.
New description:
This is similar to #26623 but a lot simpler.
The attached patch adds a "gallery_content" filter to the end of the
gallery shortcode.
It would be nice if the gallery shortcode had an available filter at the
end, before the shortcode output was returned. This would be similar to
the "the_content" filter, but just for a gallery.
I am currently trying to use a [https://wordpress.org/plugins/blueimp-
lightbox/ lightbox plugin] on a gallery, but it needs to insert an extra
attribute onto the image links. It currently utilizes the "the_content"
filter and works well on galleries added to the main content of a post.
However, I am trying run the gallery shortcode outside the main content,
so the plugin doesn't work. As far as I can tell, the plugin author
doesn't have a way to get his lightbox to work on galleries added outside
the main content or excerpt.
I can understand why the "post_gallery" filter is called so soon, for devs
who want to completely replace the functionality of this shortcode. I
don't want to replace it, nor do I want the lightbox plugin to replace
it... I want to use the standard Wordpress gallery, but with that
particular lightbox functionality added to it. This patch would allow
that.
--
Comment (by SergeyBiryukov):
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
[source:tags/4.0/src/wp-includes/post-template.php#L1487
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
);
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29832#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list