error: jQuery is not defined

[ad_1]

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,
        });
    });
});

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer