• Resolved max_Q

    (@max_q)


    Hi,

    I’m using the Lightbox plugin to generate a lightbox for a built-in WordPress gallery of site screenshots. I am using the image captions as links to the external sites by wrapping each image’s caption with an a tag on the Attachment Details page in the Media Gallery. I encountered a couple of issues using links in this way.

    The first issue is this: a couple of the website names had an apostrophe in them, which caused the data-title attribute of the a tag wrapping the image to terminate early. I solved that by wrapping the $title variable on line 117 of mpcx-lightbox.php with htmlspecialchars like so: htmlspecialchars( $title, ENT_QUOTES ). I don’t know if that’s the best way to escape html for use in an attribute, but I think it needs doing and it took care of the single quote (apostrophe) closing the attribute.

    The second issue is this: the lightbox.js script looks for any a tags with the data-lightbox attribute and the WordPress Lightbox Plugin adds that attribute to any a tag within the gallery. In my case, that includes the a tag in the figcaption element. That leads to broken previous/next functionality as the script tries to load the target of the previous/next caption link rather than the previous/next image. A little bit of jQuery to remove that data attribute from any descendant a tags of a figcaption element fixed that for me. Here’s what I used: $( “figcaption a” ).removeAttr( “data-lightbox” );

    I don’t know if this plugin supports html in captions, but seeing as how you can choose to use the description as your caption as well it would seem like it has to. It works for me now and creates a very attractive lightbox.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using links in captions’ is closed to new replies.