Tip: Add a rel attribute to WordPress gallery for lightbox use

This is really simple trick, but it’s so useful. I’m using lightboxes nearly on every WordPress project. I really love colorbox and prettyPhoto, they are my favorite. So when i create a gallery from the wordpress admin editor i want my gallery thumbnails to open in a lightbox, here is a bit of code to do it automatically:

The Code

Just paste this code in the functions.php file in your theme directory;

About the author

Remi Hey! My name is Rémi Corson, I'm a French WordPress Developer, I code stuff and I write from time to time ;-) Buy a coffee
Show your support

Related Posts

6 comments

  1. Simon Bennett:

    Nice tip. Often wondered that, thanks, that’ll be getting added to all my wordpress sites!

  2. Amber:

    Hi Rémi,

    Thanks for the great tip. Works like a charm when using a single gallery on a page.

    Do you have any tips for adding a different rel value to a custom image size (add_image_size). Using your code works great for listing a single gallery on a page. If for example I used the the gallery shortcode (listing a different set of images) in a footer widget it’s causing all gallery thumbnails on the entire page (from the the widgets gallery and the page gallery) to appear in each gallery.

  3. Syahrulzaman:

    Awesome tips. Working great on my site. Thank you so much

  4. […] may need to refer to a code snip like this to get gallery integration though, once you’ve done the […]

Leave a Reply