Fancybox is my lightbox script of choice. I feel it improves the end-user’s web-browsing experience, so I use it in most projects.
To enable Fancybox on an image, it’s necessary to:
- Surround the
<img>element with a link that points to an image file.
- Add a
data-fancyboxattribute (and optional group declaration) to the link.
Typically, you’ll be including the hyperlink along with the image when you insert it through the WordPress post editor. This code will automatically add the still-needed Fancybox attribute for you:
Other lightbox scripts are enabled similarly; this code is adaptable.