Adding lightbox overlay to default WP gallery
Sure, WP has a great inbuilt gallery feature. Unfortunately it does not allow you to change the ‘rel’ attribute for links. It’s odd that wp doesn’t already provide an option to change the rel attribute for the hyperlinks that link directly to the image attachments. Here is a simple code hack to make your WP gallery images open up in an overlay screen like lightbox or any other js modal window.
Change ‘rel’ attribute of WP default gallery
You will have to edit post-template.php in the wp-includes directory. Find the following line of code (WP 2.8 has it in line#946)
946 947 | return apply_filters( 'wp_get_attachment_link', "<a title="$post_title" href="$url">$link_text</a>", $id, $size, $permalink, $icon, $text ); |
Change the above line of code with
946 947 948 | return apply_filters( 'wp_get_attachment_link', "<a title="$post_title" rel="shadowbox[media]" href="$url">$link_text</a>", $id, $size, $permalink, $icon, $text ); |
That’s it. Now all your image attachments would open up in a lightbox. [PS: The code above will be found in a single line in post-template.php. It has been broken down into multiple lines for easy readability.]
December 14, 2009 by thinkdj in Mods Continue Reading →