How to remove gallery duplicates from Magnific Popup

I love Magnific Popup but if you use the gallery feature with the delegate option it does not remove duplicates. This was an issue for me as I was using a carousel that cloned image links and this led to duplicates. Here is how I fixed it.

Each gallery (it works with multiple galleries on the same page) should be wrapped in div.gallery and then each link to a gallery image should be a.img. This allows you to have links in div.gallery that aren’t gallery links.

Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from
Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.