Looking for a way to pre-select a certain category in your Photo Gallery widget? We’ve got a solution!
const DEFAULT_TAB = 'Category Name';
const waitForElement = (selector, root = document) =>
new Promise((res) => {
let i = 0;
const check = () => {
const component = root.querySelector(selector);
if (component) {
res(component);
} else if (i !== 50) {
setTimeout(check, 100);
i++;
}
};
check();
});
waitForElement('.eapp-photo-gallery-category-list-component').then(({ childNodes: tabs }) => {
tabs.forEach((tab) => {
if (tab.textContent.toLowerCase() === DEFAULT_TAB.toLowerCase()) {
tab.click();
}
});
});
Replace Category Name
in the 1st line of the code with the name of the needed category, and add the resulted code to the Custom JS field on the Style tab of your widget’s settings:
Guys, was this solution helpful to you? Share your experience in the comments below