How to Automatically Apply Elementor Gallery Pro Filters on Page Load

In this guide, details on how to automatically apply Elementor Gallery Pro filters on page load will be explained. By following the steps below, you can achieve the effect of automatically filtering a specific gallery on page load.

How to Filter Elementor Gallery Pro Elements to a Specific Gallery on Page Load

图片[1]-如何在页面加载时自动应用Elementor Gallery Pro过滤器-光子波动网 | WordPress教程、Elementor教程与故障修复

To set the Elementor Gallery Pro element to filter to a specific gallery, appending the URL to the ?data-gallery-index=1. This way, specific gallery filters will automatically open when the page loads.

Filters on Elementor Gallery Pro Page Load Code

move1: You need to add an HTML element on the same page as Elementor Gallery Pro. Follow the steps below:

图片[2]-如何在页面加载时自动应用Elementor Gallery Pro过滤器-光子波动网 | WordPress教程、Elementor教程与故障修复
  1. Open the Elementor editor and select the page to which you wish to add the filter.
  2. Locate the Gallery Pro element on the page.
  3. In the left panel, drag an HTML element onto the page and place it in the same position as the Gallery Pro element.

Step 2: Insert JavaScript Code

Insert the following JavaScript code into an HTML element to apply a specific filter when the page loads.

document.addEventListener("DOMContentLoaded", function() {
    // URL
    const urlParams = new URLSearchParams(window.location.search);; const galleryIndex = urlParams.get('data-gallery-')
    const galleryIndex = urlParams.get('data-gallery-index');

    if (galleryIndex) {
        //Gallery Pro element
        const galleryProElement = document.querySelector('.your-gallery-pro-class'); // replace with the actual class name of your Gallery Pro element
        if (galleryProElement) {
            // Simulate a click or selection to apply the filter
            const filterButtons = galleryProElement.querySelectorAll('.gallery-filter-button'); // replace with your actual filter button class name
            if (filterButtons[galleryIndex]) {
                filterButtons[galleryIndex].click();
            }
        }
    }
});
</script

Make sure to put the code in the .your-gallery-pro-class respond in singing .gallery-filter-button Replace it with the name of the class you are actually using.

Step 3: Update the page URL

Append the URL of the page to be filtered with ?data-gallery-index=1(or other index values), for example:

https://yourwebsite.com/your-page?data-gallery-index=1

Specific gallery filters will automatically open when the page loads.

Summary:

图片[3]-如何在页面加载时自动应用Elementor Gallery Pro过滤器-光子波动网 | WordPress教程、Elementor教程与故障修复

Get the URL of each Elementor Gallery Pro filter, which works by reusing the attributes on the Elementor Gallery Pro filter title with the following logic:

If the "All" option is present, the value is "All".

For all the others, it follows the index value, starting from 0.

firstin-"All" filtersdata-gallery-index=0. The next filter in thedata-gallery-index=1And so on.

Simply add the?data-gallery-index=0This will open the gallery filter on page load.

图片[4]-如何在页面加载时自动应用Elementor Gallery Pro过滤器-光子波动网 | WordPress教程、Elementor教程与故障修复

Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
Customer Service
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
本文作者:红牛独立站
THE END
If you like it, support it.
kudos0 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments