Using Theme Lightbox on wp-block-gallery, wp-block-image
-
I’m trying to use the lightbox (LightGallery) included in a Onepage theme (Onepress) also on the standard Gutenberg Block Gallery (wp-block-gallery) to avoid additional plugins and code.
Sample of the working homepage onepage gallery section code:
<div class="gallery-content"> <div class="gallery-grid g-zoom-in enable-lightbox g-col-3"> <a class="g-item" title="A" href="/wp-content/uploads/a.jpg"> <span class="inner"> <span class="inner-content"> <img src="/wp-content/uploads/a-480x300.jpg" alt="a" /> </span> </span> </a> <a class="g-item" title="b" href="/wp-content/uploads/b.jpg"> <span class="inner"> <span class="inner-content"> <img src="/wp-content/uploads/b-480x300.jpg" alt="b" /> </span> </span> </a> </div> </div>
Gallery page code with attempt to call the function with the “enable-lightbox” style class:
<figure class="wp-block-gallery columns-3 is-cropped enable-lightbox"> <ul class="blocks-gallery-grid"> <li class="blocks-gallery-item"> <figure> <a href="/wp-content/uploads/a.jpg"> <img class="wp-image-117" src="/wp-content/uploads/a.jpg-1024x682.jpg" alt="a" data-id="117" data-full-url="/wp-content/uploads/a.jpg" data-link="/wp-content/uploads/a.jpg" /> </a> <figcaption class="blocks-gallery-item__caption"> a </figcaption> </figure> </li> <li class="blocks-gallery-item"> <figure> <a href="/wp-content/uploads/b.jpg"> <img class="wp-image-124" src="/wp-content/uploads/b-1024x640.jpg" sizes="(max-width: 1024px) 100vw, 1024px" srcset="/wp-content/uploads/b-1024x640.jpg 1024w, /wp-content/uploads/b-300x188.jpg 300w, /wp-content/uploads/b-768x480.jpg 768w, /wp-content/uploads/b-1536x960.jpg 1536w, /wp-content/uploads/b-480x300.jpg 480w, /wp-content/uploads/b-640x400.jpg 640w, /wp-content/uploads/b.jpg 1800w" alt="b" data-id="124" data-full-url="/wp-content/uploads/b" data-link="/gallery/b/" /> </a> <figcaption class="blocks-gallery-item__caption"> b </figcaption> </figure> </li> </ul> </figure>
By adding the frontpage code as a HTML element in the subpage it did work as on the frontpage.
I was also not able to get it to work on <div class=”wp-block-image enable-lightbox”>
Best solution would be a function in the child theme so that all galleries and images use this lightbox, but here I would need advise to possibly get to that.I wonder why “enable-lightbox” class works on the DIV element in the frontpage while it seems without effect on the FIGURE and DIV element in a subpage?
Has someone experience and was able to do this or a similar lightbox by class?
- The topic ‘Using Theme Lightbox on wp-block-gallery, wp-block-image’ is closed to new replies.