Learn in this tutorial how to make the images to open in lightbox on the pages you want, with a little bit of code.
Starting with WordPress 6.4, a lightbox feature was added that allows you to click on an image to enlarge it. However, by default the option is disabled and therefore all the images you have already entered will not be enlarged using this effect.
You can change this setting easily from the block sidebar, but if you have a lot of images it can be quite tedious to change them all manually.
In this tutorial I’m going to show you how to get the setting to turn on automatically on certain pages.
So that when the users visit, for example, the portfolio entries, when they click on the images they will open in a lightbox.
Let’s see how.
Snippet to display images in lightbox on specific pages and/or posts
Here are two examples, to apply them add the snippet that interests you to functions.php or to your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
And these are just a couple of examples. Using WordPress conditional tags you can control in a very granular way on which pages and posts the images will be enlarged when clicked on.
In an installation with a lot of images this strategy can save you a lot of hours.
Conclusions
Do you want that some images that were already in WordPress can be enlarged by clicking on them (lightbox effect)? And better yet, that they do so depending on the page or post?
Well now you know how to get it.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂