31 May 2013

Single thumbnail WordPress gallery

single thumbnail wordpress gallery

By default WordPress’s built-in gallery shortcode outputs all thumbnails for each gallery. But what if you don’t want the clutter of lots of thumbnails?

The default gallery output code can be found in wp-includes/media.php. All you have to do is take this, customise it however you like, drop your customised code into a function and hook it to the gallery filter action using add_filter().

Here’s something I came up with for a recent project. This outputs a thumbnail for the first gallery item and a bunch of links for all others. Using this, you can hide the links using CSS and open up the gallery directly from the first thumbnail using fancybox or lightbox.


Hide the plain links with your preferred method, e.g.

Then simply append your links with whatever attributes are necessary for your lightbox using the same add_filter() method, e.g.