


document.addEventListener(“DOMContentLoaded”, function () {
document.querySelectorAll(“.wp-block-gallery”).forEach(function(gallery){
const figures = gallery.querySelectorAll(“figure”);
if(figures.length < 2) return;
let current = 0;
figures.forEach((fig,index)=>{
if(index!==0){
fig.style.display=”none”;
}
});
gallery.style.position=”relative”;
const prev=document.createElement(“button”);
const next=document.createElement(“button”);
prev.innerHTML=”❮”;
next.innerHTML=”❯”;
[prev,next].forEach(btn=>{
btn.style.position=”absolute”;
btn.style.top=”50%”;
btn.style.transform=”translateY(-50%)”;
btn.style.background=”rgba(0,0,0,.5)”;
btn.style.color=”#fff”;
btn.style.border=”0″;
btn.style.padding=”10px 15px”;
btn.style.cursor=”pointer”;
btn.style.zIndex=”99″;
});
prev.style.left=”10px”;
next.style.right=”10px”;
gallery.appendChild(prev);
gallery.appendChild(next);
function show(i){
figures.forEach(f=>f.style.display=”none”);
figures[i].style.display=”block”;
}
next.onclick=function(){
current=(current+1)%figures.length;
show(current);
}
prev.onclick=function(){
current=(current-1+figures.length)%figures.length;
show(current);
};
});
});