This code adds a rel attribute to output gallery link tags for custom lightbox scripts to allow the JavaScript to pick them up as a lightbox.
// Add rel tag to gallery images (Used for some Lightbox plugins / code)
function addlightboxrel_replace($content){
global $post;
$pattern = "/<a(.*?)href=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)>(.*?)</a>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="gallery"$6>$7';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'addlightboxrel_replace', 12);
add_filter('get_comment_text', 'addlightboxrel_replace');