How to show image captions in a lightbox

How to show an image with a caption or author information in a lightbox in WordPress.

WordPress 6.4 introduced an option to extend images on click and show a larger version in a lightbox.

Until now, I used third-party plugins, which I will now remove step by step from many of my sites.

Show an image in a lightbox

To extend an image, insert it into the block editor and find the “Expand on click” checkbox in the block options.

Expand on click option in WordPress to show an image in a lightbox.
(Click to see the whole screen)

Right now, you need to enable this option for each image individually. I believe that a general option to extend all images by default might be added in a future release.

The image will extend when a user clicks on it in the frontend when enabled. The visualization of this is also known as a “lightbox” or “fancy box.”

Note: The lightbox option is disabled when the image is wrapped in a link.

Captions are missing

Of course, I had to check how WordPress captions, in general, and Image Source Control’s author attributions, in particular, are handled in the lightbox.

The WordPress caption is missing entirely.

This is not a deal breaker to me, though I consider captions helpful – if used correctly.

Btw., the lightbox plugin I previously used showed the caption.

Author information shows up

The author information overlay, added by Image Source Control, was also missing when I tested the first release candidates for the lightbox feature in WordPress 6.4.

Eventually, it started to show up with changes closer to the release date.

I only had to change some CSS to make a few overlay positions compatible with extended images.

You can see it working in the animation above.

With this feature’s current momentum, I expect a few changes in the next releases and will try to test them for compatibility.

Questions from readers

Are galleries supported?

As of February 2024, one can enable the lightbox option for individual images in a gallery, but there is no navigation between images yet. There are feature requests for this in core, but no deadline given.

Conclusion

The lightbox feature will replace dedicated plugins on many sites. I am excited to use it myself.

However, on this very site, I am still using Easy FancyBox. It supports lightboxes on more than just images, and I can show a different picture in the lightbox than the original one, which I did above when showing the block option. The first animation in the content uses the new WordPress lightbox.

Portrait of Thomas Maier, founder and CEO of Image Source Control

Questions? Feedback? How can I help?