Elementor Pro Gallery - Add Different Links to Each Image
No extra plug-ins required! Elementor Pro Required.
Updated 26 June 2023
Here is how to easily add a different link to every image in the new Elementor Pro gallery element! These Elementor gallery links are not yet available directly from that element’s settings.
Probably Elementor will add this functionality soon, but meanwhile here is a way to make this work.
Working examples:
Also works with multiple galleries:
To begin with, set your Elementor Pro gallery "link" setting to "custom"
Important: videos watchers, these instructions aren’t in Imran’s video!
This will create the proper HTML markup that we need for the code to work. It will wrap each image in a <a> element.
Find the Link setting, and set it to Custom URL. Then in the URL bar, enter “#”.
Now, add an HTML element on the page with that Elementor Pro Gallery
It doesn’t really matter where on the page the Element is added…
Then, add this code the html element, and edit the links to your own
The first link will be automatically linked with the first image in the gallery, and so on. Add a link for every image.
<script> /* Please login to get the code * The code will be for the [Pro] Elementor Gallery Links - Unique Link for Each Image tutorial * Found at this URL https://element.how/elementor-gallery-links-pro/ */ </script>
Opening links in a new window (or new tab) [optional]
To open the links in a new tab instead of opening in the same window, add this code
<script> /* Please login to get the code * The code will be for the [Pro] Elementor Gallery Links - Unique Link for Each Image tutorial * Found at this URL https://element.how/elementor-gallery-links-pro/ */ </script>
directly below this line of code
linkedImage.href = links[i];
Want to skip an image?
If you want to skip an image, ie don’t have a link for it, simply enter no URL for it’s place in the list.
So let’s say you have 3 images, and you want to skip image 2. Your links variable becomes:
let links = [
'https://element.how/elementor-pop-ups-problems/',
'',
'https://element.how/amazing-accordion-section/',
];
Extra: Want these Elementor Gallery Images to open a Popup ? Use this code instead.
You will need to add the class name popupGallery to your Gallery Pro element, under Advanced > CSS classes.
Check this image to find your popup IDs.
Add this code in your HTML element:
<script> /* Please login to get the code * The code will be for the [Pro] Elementor Gallery Links - Unique Link for Each Image tutorial * Found at this URL https://element.how/elementor-gallery-links-pro/ */ </script>
![[Pro] Elementor Gallery Links - Unique Link for Each Image 1](https://cdn.element.how/wp-content/uploads/2023/06/make_clickable_gallery_pro_set_link.png)
Hi Maxime, thanks for your response. I am not using the Image Carousel. I am using the Gallery Pro element, as I wanted the option to use the offset sides feature. I guess i could switch to the Image carousel but that one doesn't have the offset sides feature.
How can I make this work with what i'm using, the Gallery Pro element?
The Gallery Pro element isn't a slider though...
I see you are using the new Carousel element (e-n-carousel), and have normal Images element in it.
Just set your links directly on the Images elements, it should work. You don't need any custom JavaScript.
Cheers!
... Is there supposed to be something entered where the "i" is, ex. links[i]? I have 8 images, to start.
linkedImages.forEach((linkedImage, i) => {
if (links[i] && links[i].length > 0) {
linkedImage.style.cursor = "pointer";
linkedImage.href = links[i];
Hi Maxime, I have a gallery in a footer that I want to include links. Your code works great for this. But on some pages I have another gallery, and that is above the footer. The url's apply to that gallery first. Is there a way I can target a specific gallery?
Greetings Matt!
Yes certainly.
Change this line:
let linkedImages = document.querySelectorAll('.e-gallery-item');
To this:
let linkedImages = document.querySelectorAll('.footer-gallery .e-gallery-item');
And then give the class name footer-gallery to your footer gallery.
Cheers!
Hi Maxime,
I have used the code but the images doesn't open a new browser. What have I missed here? thanks
Greetings Mani,
Without a URL I can't help much.
Cheers!
Hey !
Thanks a lot for this tutorial. As some of people there, I had issues about the "random" sorting.
I found an other way :
Add an HTML link in the caption field of each image. This isn't ideal, nor probably best practice, but it works for me.
<a href="http://Internet URL goes here.">Title the visitor sees.</a>
Next, you need to set the Overlay->Title option in the Elementor Gallery widget to Caption.
I'd love to know if this works for you.
BR
Arthur
Thanks for sharing Arthur!
Hi, this worked perfectly. This might be a silly question, but I've added a second gallery to the same page and just want these images to have the lightbox display setting rather than individual links. The lightbox function isn't working properly on the front end for the second gallery on the page. Is this due to the code on the page? Is there a workaround for this? Thanks!
Greetings Smason!
In that case, you will need to add a class name 'gallery-with-links' to the gallery you want to target, and then in the code, change this line
let linkedImages = document.querySelectorAll('.e-gallery-item');
to this
let linkedImages = document.querySelectorAll('.gallery-with-links .e-gallery-item');
Cheers!
Thanks so much, that worked perfectly!
It is not working with multiple filtered gallery. How can i redirect my links to filtered items? Please Help
Greetings!
It should be working just fine with multiple filter galleries, as indeed you can even see a working example on this very page!
Cheers!
Thanks for the prompt response, but it is not working with filtered gallery. Kindly please help me.
Greetings!
Share your URL, I will have a look.
https://wajihaattique.com/work/
Kindly check out the website tab of this page. There I've used multiple filtered gallery widget. Thanks
Greetings!
You need to make your images links.
Please see the first part of this written tutorial, about "To begin with, set your Elementor Pro gallery "link" setting to "custom"
Cheers!
I have followed the eac and every step according to the video. It perfectly works with single gallery option but not working with multiple fiiltered gallery. I have made the link to custom URL as you described in the video but still I am facing issues.
Greetings!
I can see from the DOM that they are not links.... follow the instructions very carefully please, in the tutorial, not the video.
Cheers!
Youre a hero
Hello all!,
Can I replace the web links for anchors to use the images of the image gallery to navigate through my site?.
Thanks in advance!
Greetings!
You could, but it's not a great idea to use this as your primary navigation.
You can't add proper ALT text as the images are actually background images from the CSS, and not proper <img> elements...
Instead, you should look at this tutorial:
Elementor Horizontal Scroll Menu, Taxonomy, Tabs With Extra Features
Cheers!
Hi Maxime!,
Thank you very much for your quick response.
I'll take a look to the tutorial.
Best!,
Juan
Olá, teria como eu utilizar esse codigo utilizando as URL ja atreladas as imagens? Pra evitar ter que adicionar manualmente cada link
Sorry this isn't possible with this tutorial.
Hi Maxime! I used this code and it was working fine when I first launched my site, but now it's stopped working. I don't know what could have happened. My URL is: redchoux.com and here is the code I have:
<script>
document.addEventListener('DOMContentLoaded', function () {
let linkedImages = document.querySelectorAll('.e-gallery-item');
let links = [
'https://redchoux.com/senior-photography/',
'https://redchoux.com/professional-headshots/'
'https://redchoux.com/healthcare/',
'https://redchoux.com/family-photography/',
'https://redchoux.com/event-photography/',
'https://redchoux.com/photo-restoration/',
];
linkedImages.forEach((linkedImage, i) => {
if (links[i] && links[i].length > 0) {
linkedImage.style.cursor = "pointer";
linkedImage.href = links[i];
}
});
});
</script>
Greetings Michele!
You need a comma after this URL:
'https://redchoux.com/professional-headshots/'
Cheers!
Thank you for this edit correction, but the links still aren't working. Not sure what I've done wrong.
Greetings Michele!
Follow the instructions at the very start of the tutorial to make each image a link, the part called " To begin with, set your Elementor Pro gallery "link" setting to "custom" "
Cheers!
Thank you! I was missing the # in the URL field. Thank you!
HI THERE!
I used the HTML code to open the Elementor Pro Gallery image links, and everything worked perfectly, but NOW only my images with the ULR wp/content/upldoads (which opened with Lightbox), stopped opening in the latest Elementor update. Do I have to change the code so that they open with POPUP? I prefer it to continue as it was before, with the images opening in Lightbox.
Can someone help me, please?
Hey there!
Quick question for someone, I'd appreciate the help!
So, I've added the HTML code to the top of my Elementor Pro Gallery and it works great with the link-out to new window code. However, when I get past my first row of images, 5, it's not linking the URL to the following images. I'm adding the urls within the parameters set in the code and adding them as described, for example: 'url', 'url', but for some reason, it's not adding the URL to the images following the first row.
I need to add URLs to 15+ images within the gallery.
This is probably a user error but if anyone has any insight, I'd greatly appreciate the assist!
Greetings!
Please share your URL I will have a look.
Thank you, Maxime! Here's the code I have so far. The first five are working, however the last two are not just yet.
<script>
document.addEventListener('DOMContentLoaded', function () {
let linkedImages = document.querySelectorAll('.e-gallery-item');
let links = [
'https://www.imdb.com/title/tt11348164/?ref_=fn_al_tt_1',
'https://www.imdb.com/title/tt13395224/?ref_=nv_sr_srsg_0_tt_8_nm_0_in_0_q_country%2520gold',
'https://www.imdb.com/title/tt13988984/?ref_=nv_sr_srsg_2_tt_6_nm_2_in_0_q_tenkiller',
'https://www.imdb.com/title/tt15330144/?ref_=nv_sr_srsg_0_tt_7_nm_1_in_0_q_seven%2520cem',
'https://www.imdb.com/title/tt18552372/?ref_=nv_sr_srsg_0_tt_1_nm_7_in_0_q_fairwood',
'https://www.imdb.com/title/tt12661008/?ref_=nv_sr_srsg_0_tt_8_nm_0_in_0_q_out%2520of%2520exile',
'https://www.imdb.com/title/tt10474680/?ref_=nv_sr_srsg_0_tt_7_nm_1_in_0_q_chicken%2520house',
];
linkedImages.forEach((linkedImage, i) => {
if (links[i] && links[i].length > 0) {
linkedImage.style.cursor = "pointer";
linkedImage.href = links[i];
linkedImage.setAttribute('target','_blank');
} else {
linkedImage.removeAttribute('href');
}
});
});
</script>
Please share your page where you have this
https://oksoundsgood.pro/work/
Simply add a link for every image. You can't have a partial list.
Hope this helps!
Awesome and yes, but is there any reason why they aren't linking out from the code I posted?
And keep in mind when you are using masonry that the order of the images isn't 'as they show up on the screen', but 'as they show up in the DOM'.
So right click> inspect to get the proper order, but it think it should match the order that you have them when you are selecting them in the Elementor UI.
Hope this helps!
oohhh okay! yes, that makes more sense. Thank you for your help!
Thank you VERY much!
How do I use this in in a popup?
So I want to add theis gallery on a page and then when you click on an image it opens a popup I make (not the lightbox) where the same gallery is inserted (but bigger and full screen) then it scroll down to that target image.
So lets say I click image 4 on the page, a popup comes on screen and scroll to image 4.
Greetings!
Sorry this is quite complex, and not really what the current tutorial is about...
The closest I have to what you are asking is the following tutorial: Elementor Open Popup To A Specific Carousel Slide
I hope it helps!
I've had this WORKING on my website for about 6 months... last week with no changes it stopped. Did Elementor make an update or something to where the code doesn't work?
Andrew, I used this code just today, with the latest Elementor Pro update (v. 3.26.3). Code works beautifully.
Still works fine, as you see in my demo above... try starting fresh!
Max, you're really the best!!
P.S.
Max, funny thing: I was playing around with it on my other pages with a gallery. I mistakenly set the link to "media file" instead of "custom url". And what do you know - clicking the images took me to the URLs I specified in the code! Was that a fluke or what?
Indeed the code should still work fine even if you select media file.
Cheers!
Hi Max, thanks for your sharing... I tried many times, but it doesn't work for me, the cursor changes when I hover, but nothing happens if I click, could you give me an insight? Thank you so much!!
My code is:
<script>
document.addEventListener('DOMContentLoaded', function () {
let linkedImages = document.querySelectorAll('.e-gallery-item');
let links = [
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
'https://www.erzoarts.com/',
];
linkedImages.forEach((linkedImage, i) => {
if (links[i] && links[i].length > 0) {
linkedImage.style.cursor = "pointer";
linkedImage.href = links[i];
linkedImage.setAttribute('target','_blank');
} else {
linkedImage.removeAttribute('href');
}
});
});
</script>
My page is: https://erzoarts.com/gallery/
Hey Marco!
Looks like it's because of the ;, you have at the end of each line... it needs to be just a ,
Hi this looks great. I'm wondering if there is a way to have the each gallery image pop up into the lightbox as it does without this HTML code snippet, and then be clickable to go to a URL (specifically the product purchase page of the item). I am trying to make an aritst portfilio, that shows the gallery, but then can click the image to show it in the lightbox larger, but then be clickable to go to purchase, if that makes sense. Perhaps I am just trying to complicate things or maybe there is an easier way to do it that what I am attempting.
Thanks for any help
Sorry this tutorial can't do what you want here, it's complex and unfortunately out of scope for this tutorial.
Hi,
Thanks for the clear explanation on this page! I'm trying to apply the gallery links as described, but unfortunately it's not working properly on my end. On my website (https://bureaublikwerpen.nl/sponsoren/), I'm using a gallery with Elementor, but the links aren't opening as expected.
Could someone take a look to see if I might be missing something or if there's a conflict? Any help would be much appreciated!
Thanks in advance!
Hey Justin!
This tutorial is specifically for the Gallery Pro elementor element that comes with Elementor Pro. On your website you are using another gallery element, it won't work with that one.
I hope this helps!
Hello
I have several galleries. Surprisingly, in one gallery, the code works with the "Media File" link and not with the "Individual Link" with "#." In the other gallery, the code doesn't work.
Best
Martin
i have found the error. i forgot the ' after one link!
It worked great! Thanks so much!