Hi,
I’ve just installed the plugin and tried to use it out of the box – but having some issues. I’ve set to V2, chose the post types I want to use it on and enabled the option to work for standard WordPress galleries. However it would not work, jumped into the code and found that ‘in_the_loop’ in if ( is_singular() && in_the_loop() && is_main_query() ) { is preventing the inline js from getting added to the page as in_the_loop == 0.
We are using WP Bedrock & Timber a little different to a standard installation
Great plugin other than this, but just thought I’d provide this feedback incase anyone else is having the same issue.
Kind regards,
Thomas Brentnall
]]>I’m just contributing code that works (for me) with the native Gallery block and this plugin:
document.addEventListener("DOMContentLoaded", function() {
// Select all divs with an ID starting with "gallery-"
document.querySelectorAll('.wp-block-gallery').forEach(function(gallery) {
// For each gallery item within this gallery div
gallery.querySelectorAll('.wp-block-image').forEach(function(item) {
// Retrieve the text inside the figcaption element (if exists)
const caption = item.querySelector('figcaption');
const captext = caption ? caption.textContent : '';
// Add the data-sub-html attribute to the corresponding <a> element
const link = item.querySelector('a');
if (link) {
link.setAttribute('data-sub-html', captext);
}
});
// Use className property of <figure> gallery element as ID because it is unique
const id = gallery.className;
// Do something with each selected div
lightGallery(gallery, {
plugins: [lgFullscreen, lgMediumZoom, lgVideo, lgZoom, lgPager],
selector: 'a',
galleryId: id,
});
});
});
]]>
I love this plugin and hope to assist with its development!
my site doesn’t use jQuery. your plugin assumes it is available and generates inline script even if “v2.7.0” is the lightGallery version chosen, so i get the error that jQuery is not defined.
so I am going to give you the code it generated inline as vanilla JS. let me know if you want help rewriting anything else to vanilla JS, which should work better regardless of the version used:
document.addEventListener("DOMContentLoaded", function() {
// Select all divs with an ID starting with "gallery-"
document.querySelectorAll('div[id^="gallery-"]').forEach(function(gallery) {
// For each gallery item within this gallery div
gallery.querySelectorAll('.gallery-item').forEach(function(item) {
// Retrieve the text inside the figcaption element
const caption = item.querySelector('figcaption').textContent;
// Add the data-sub-html attribute to the corresponding <a> element
const link = item.querySelector('a');
if (link) {
link.setAttribute('data-sub-html', caption);
}
});
// Get the ID of the current div
const id = gallery.id;
// Use a regular expression to extract the number from the ID
const number = id.match(/\d+/)[0];
// Do something with each selected div
lightGallery(gallery, {
plugins: [lgFullscreen, lgMediumZoom, lgVideo, lgZoom],
selector: 'a',
galleryId: number,
});
});
});
]]>
Simple lightGallery works when displaying a vanilla WP gallery.
However when a plugin such as ‘Tiled Galleries Carousel Without Jetpack’ is enabled, Simple lightGallery doesn’t work at all. This is because Tiled Galleries does not load a < figure > tag. When I remove the figure tag from the DOM for a standard thumbnail display this breaks lightgallery from loading. Standard Jetpack also doesn’t utilize the figure tag around it’s thumbnails:
https://jetpack.com/support/carousel/
Is there any way to remove the figure tag requirement?
]]>Howdy, hoping all is well.
When activating the checkbox ‘relativeCaption’ in LightGallery v2.7.0 it doesn’t display a photo caption in the lightgallery. Just to be double sure I used control+F which only pulls up the caption in the thumbnails shown on the post. When lightbox is open it doesn’t highlight. Then I opened up the browsers inspector with lightbox opened which the caption text only appears below the thumbnail image in post but not in lightgallery.
]]>I see an option for hash, but it doesn’t appear to update the URL hash when navigating the gallery.
]]>How can I get this working? On images that are linked to the media file?
or is there a way to add a Custom grouping selector(s)?
thank you. Would love to get this plugin working. My theme has custom galleries that don’t use the gallery wordpress tag.
]]>