2

Using the script Lightbox2 I would like to place a link (<a> tag) in the description of the image.

For example:

I would replace "Click the right half of the image to move foward." with Visit My site!

Watch this Image enter image description here

Daniel Corzo
  • 1,055
  • 2
  • 19
  • 32
MItaly
  • 23
  • 1
  • 5

1 Answers1

8

You can add a link in the caption by simply adding the anchor tag in the data-title attribute. For example:

<a href="image.jpg" data-lightbox="example" data-title="Optional <a href='http://google.com'>caption</a>.">My image link</a>

The ability to add anchor tags directly in the data-title attribute without having to encode them first was added in version 2.7.2 on 2015-06-16. Make sure to upgrade if you're using an older version, as this option won't work in older versions of the plugin:

http://lokeshdhakar.com/projects/lightbox2/

Lokesh Dhakar
  • 5,289
  • 5
  • 22
  • 24
  • 1
    How can i encode the link into the `data-title` attribute. I'm using Twig templates – r3wt Dec 17 '15 at 16:33
  • very nice solution. what if I want to add an onClick event in that link, say onClick='alert(my name here)' ? – armen Sep 13 '18 at 09:17