Last night, I posted my first ever native WordPress gallery (old dog, new tricks, etc). The thumbnails were pretty enough, but clicking through to a clunky WordPress “attachment page” – or worse, a raw JPEG file – was too much hard work, so I went looking for a Lightbox plugin for WordPress.
Enter Lightbox Plus ColorBox. Install, check the “Use for WordPress Galleries” option, enable Fancypants styling, done!
Well, almost. It turns out ColorBox doesn’t play nice with captions as rendered by WordPress. I needed to insert this above the wp_footer()
call in the theme:
<script type="text/javascript"> jQuery(document).ready(function($){ $(".gallery img").each(function(){ var alt = $(this).attr("alt"); $(this).parent().attr("title",function(i,val){ return val == alt ? "" : alt; }); }); }); </script>
It replaces image titles with their respective captions, unless the caption and title are the same, which would suggest no caption has been specified.
You’re welcome.
Handy. Thank you.
Thank you, thank you, thank you, thank you!!! :)
It worked for me on latest WP, THANKS!!!!
Hey, snappy, simple, it works. Thanks a ton!
Lifesaver, thank you so much for sharing.
Worked with plugin version 2.7 and WordPress version 4.0.