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

Remi | August 8, 2012 | in Tips

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;

The author

About the author Remi: Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!


  1. 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.

  2. Pingback: Display Gallery Images from Custom Post Type | DL-UAT

Leave a reply