Closed arraypress closed 4 years ago
It be interesting to have a lightbox ToggleControl appended to the InspectorControls of the core image/gallery blocks, to give users the option to turn on lightbox for any image/gallery. 🤔
How possible is this @AnthonyLedesma?
As per discussion with my friend Rich Tabor, I wanted to use the beautiful CoBlocks included lightbox on other elements throughout my site to minimise bloat and plugin requirements.
The issue is the lightbox JS file required is loaded dynamically when a CoBlocks "carousel" block is used via has the
has_block
function, so I had to build a custom function within my child theme to get around this, here it is:The light-box looks for one class on the parent div of the gallery, which is
has-lightbox
. You can add this under the "Advanced" tab on the sidebar.Once you have done this, the lightbox can be used on any page with a gallery. Hopefully someone else can benefit from this!
It's worth noting that you can probably filter those classes and add the class automatically, but I wanted to avoid this so I had more control over which galleries it acts on.