Change WordPress default gallery output

change-gallery-output-wordpress

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):

(Source)

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 wp_prepare_attachment_for_js() function:

(Source)

Just paste it to your functions.php file and modify to adapt it to your need.

Save

Author: Leo

My name is Leo who's behind this blog. I've been working with wordpress since 2010. I'll write about themes, plugins, tutorials and all about wordpress here. Hope you find it useful!

8 thoughts on “Change WordPress default gallery output”

  1. What if I don’t want to change all galleries, but rather only a few? Is there a way to change this to add a new gallery shortcode and target my changes to only the galleries with the new shortcode?

  2. Hi,

    thank you for your tutorial!

    Is it possible to add a link to the image full size in each miniature ?

    Thanks

    Thierry

Leave a Reply

Your email address will not be published. Required fields are marked *