Gallery feature made it easy to add one or more images into a post with a simple shortcode. While we may occasionally want to change the gallery output to better meet our requirements, like to showcase the images using a third party js plugin.
There’s a filter to
post_gallery which you can use to customize all default WP galleries.
Following is the code I found the other day and it works just pretty good to customize the WordPress gallery output.
The first part of the function is pretty much gallery attachments handling, so you’ll probably just want to change the latter half, the one that determines the output of your gallery template (follow the comments):
If you are in need of including the Caption, just make some improvement in the latter part of above codes. Here we can use the
Just paste it to your
functions.php file and modify to adapt it to your need.