Redirect specific image from a gallery to a specific link according to the default url of the media

[ad_1]

Hi guys, I have an Elementor multiple Gallery. A few of the images have to be clickable and to redirect to a specific link. I tried to do it whit the following code. My goal was to identify the image by the default url of the media and then say to it, if you have this specific link, redirect to that link:

document.addEventListener(‘DOMContentLoaded’, function () {

​

var links = {

/\*url of the image\*/ “[https://arc-architecture.ch/wp-content/uploads/2023/05/Appartements-PPE-Reconvilier-e1686143826933.jpg]”:/\*link where this specific image should send\*/ ‘[https://arc-architecture.ch/appartement-ppe-a-reconvilier/]’,

“[https://arc-architecture.ch/wp-content/uploads/2023/05/autreImage.jpg]”: ‘[https://example.com/link2]’,

};

​

var images = document.querySelectorAll(‘.e-gallery-item img’);

images.forEach(function (img) {

var src = img.getAttribute(‘src’);

var link = links\[src\];

if (link && link.length > 4) {

img.parentNode.style.cursor = “pointer”;

img.parentNode.addEventListener(‘click’, function () {

window.location = link;

});

}

});

});

​

Thanks a lot guys !

[ad_2]

 

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