Since I don't yet have enough reputation points to comment, I'm commenting here, in addition to providing a solution.

Comment: JSFiddle isn't working with your http:// images because JSFiddle is trying to serve them from https://

Solution:

You are halfway there. There are 2 parts to making the captions work.

  1. You correctly have put the link in the anchor tag and not the image tag
  2. You must specify your title source in your initialization script like this.

    $(document).ready(function() {
        $('.chicken').magnificPopup({ 
            type: 'image',
            gallery:{enabled:true},
            type: 'image',
            image: {
                titleSrc: 'title' 
                // this tells the script which attribute has your caption
            }
        });
    });
    

The script then automatically writes your caption to its div labeled class="mfp-title"

BONUS Solution: I needed my lightbox image to open in a new window for users on their phones to zoom in, so I added this after the first titleSrc declaration:

    titleSrc: 'title',
    titleSrc: function(item) {
        return '<a href="' + item.el.attr('href') + '">' + item.el.attr('title') + '</a>';
        }

This information is in the documentation: http://dimsemenov.com/plugins/magnific-popup/documentation.html in the "Image Type" section

Answer from JessycaFrederick on Stack Overflow
🌐
Dimsemenov
dimsemenov.com › plugins › magnific-popup › documentation.html
Magnific Popup Documentation
By default, Magnific Popup has four types of content: image, iframe, inline, and ajax.
🌐
GitHub
gist.github.com › hirejordansmith › 1ac659aadc1d720f505b28a1540d6547
How to show images and video in Magnific Popup Gallery · GitHub
I've corrected the code and made HTML example: https://github.com/sunzxs/magnific-popup-image-and-video-slider ... Hi, Sunzxs Thanks for sharing example.. I have download all files & run example. But I don't have open video popup. can you please share update or any solutions for that. Thanks advanced. ... <script> $(document).ready(function() { $('.popup-gallery').magnificPopup({ delegate: 'a', type: 'image', gallery: { enabled: true, navigateByImgClick: true, preload: [0, 1] // Will preload 0 - before current, and 1 after the current image }, callbacks: { elementParse: function(item) { if(item.el[0].className == 'video') { item.type = 'iframe'; } else { item.type = 'image'; } } }, }); }); </script>
Discussions

css - How to include caption for gallery using magnific popup? - Stack Overflow
I am trying to include a caption on the actual webpage under the image while using the magnificence popup gallery. Using a div and class caption or carousel-caption, I am unable to do so without the images in the gallery stacking vertically one by one. More on stackoverflow.com
🌐 stackoverflow.com
jquery - Magnific Pop-Up - Show different gallery depending upon image clicked - Stack Overflow
The issue I have is that regardless ... single image. I'd like to know if any body else has encountered this issue and if they have whether they found a clean way around it, rather than having to give each gallery set a unique id. Documentation is here: http://dimsemenov.com/plugins/magnific-popup/documentation.html ... More on stackoverflow.com
🌐 stackoverflow.com
jquery - Magnific Popup – Image gallery inside of modal box - Stack Overflow
I've used the great magnific popup for inline content modal box. There is an image gallery in this modal, which I'd like to use the magnific popup for too. Is there any way of going "one level deep... More on stackoverflow.com
🌐 stackoverflow.com
March 22, 2017
How can I get magnific popup to show both images and an iframe video in one dynamic gallery?
I am using magnific popup to create an image gallery via the below: $('.main-content').magnificPopup({ delegate: '.gallery', // child items selector, by clicking on it popup will open type: 'i... More on stackoverflow.com
🌐 stackoverflow.com
🌐
CodePen
codepen.io › kisa007 › pen › xxbZOxv
Simple Image Gallery with magnific-popup.js
$(document).ready(function(){ $('.image-popup-vertical-fit').magnificPopup({ type: 'image', mainClass: 'mfp-with-zoom', gallery:{ enabled:true }, zoom: { enabled: true, duration: 300, // duration of the effect, in milliseconds easing: 'ease-in-out', // CSS transition easing function opener: function(openerElement) { return openerElement.is('img') ?
🌐
GitHub
github.com › solodev › magnific-popup-photo-gallery
GitHub - solodev/magnific-popup-photo-gallery: Whether you're showcasing your work or team - displaying images on the web is commonplace but how you display them is another matter altogether. Solodev customizes the Magnific Popup plugin to create outstanding photo galleries.
$(document).ready(function() { $('.popup-gallery').magnificPopup({ delegate: 'a', type: 'image', tLoading: 'Loading image #%curr%...', mainClass: 'mfp-img-mobile', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] // Will preload 0 - before current, and 1 after the current image }, image: { tError: '<a href="%url%">The image #%curr%</a> could not be loaded.', titleSrc: function(item) { return item.el.attr('title') + '<small>by WebCorpCo</small>'; } } }); });
Author   solodev
🌐
Dimsemenov
dimsemenov.com › plugins › magnific-popup
Magnific Popup: Responsive jQuery Lightbox Plugin
Three simple popups with different scaling settings. 1 — fits horizontally and vertically, 2 — only horizontally, 3 — no gaps, zoom animation, close icon in top-right corner. You may put any HTML content in each gallery item and mix content types. In this example lazy-loading of images is enabled for the next image based on move direction.
🌐
CodePen
codepen.io › bluminethemes › pen › bpPvvb
Magnific Popup - Open gallery with single image
June 8, 2024 - $(document).ready(function() { $('a.btn-gallery').on('click', function(event) { event.preventDefault(); var gallery = $(this).attr('href'); $(gallery).magnificPopup({ delegate: 'a', type:'image', gallery: { enabled: true } }).magnificPopup('open'); }); });
Top answer
1 of 2
13

Since I don't yet have enough reputation points to comment, I'm commenting here, in addition to providing a solution.

Comment: JSFiddle isn't working with your http:// images because JSFiddle is trying to serve them from https://

Solution:

You are halfway there. There are 2 parts to making the captions work.

  1. You correctly have put the link in the anchor tag and not the image tag
  2. You must specify your title source in your initialization script like this.

    $(document).ready(function() {
        $('.chicken').magnificPopup({ 
            type: 'image',
            gallery:{enabled:true},
            type: 'image',
            image: {
                titleSrc: 'title' 
                // this tells the script which attribute has your caption
            }
        });
    });
    

The script then automatically writes your caption to its div labeled class="mfp-title"

BONUS Solution: I needed my lightbox image to open in a new window for users on their phones to zoom in, so I added this after the first titleSrc declaration:

    titleSrc: 'title',
    titleSrc: function(item) {
        return '<a href="' + item.el.attr('href') + '">' + item.el.attr('title') + '</a>';
        }

This information is in the documentation: http://dimsemenov.com/plugins/magnific-popup/documentation.html in the "Image Type" section

2 of 2
6

I tried to use the selected answer, but even using the documentation, the examples wouldn't work for me. What I ended up using was:

$('.elements').magnificPopup({
   type: 'image',
   gallery: {
       enabled: true
   },
   image: {
       titleSrc: function(item) {
          return item.el.find('img').attr('title');
       }
   }
});

This probably has something to do with the version I was using, but it wasn't clear what version the documentation was for. Hopefully this is useful to someone.

Find elsewhere
Top answer
1 of 1
2

You can create two separate magnificPopup for both parent..

$('.imageParent').each(function() {
    $(this).magnificPopup({
        delegate: 'a.zoom',
        type: 'image',
        gallery: {
            enabled: true,
            preload: [0,2]
        }
    });
});

$('.imageParent').each(function() { 
    $(this).magnificPopup({
        delegate: 'a.zoom',
        type: 'image',
        gallery: {
            enabled: true,
            preload: [0,2]
        }
    });
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.js"></script>
<span class ="imageParent parent1">
    <a href="#" target="_blank">
        <span class="portfolio-links">
            <span class="ion-ios-arrow-right portfolio-links-icons">noimage</span> 
        </span>
    </a>&nbsp;
    <a href="https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350" class="zoom" >
        <span class="portfolio-links">
            <span class="ion-arrow-expand portfolio-links-icons">image 1</span> 
        </span>
    </a>&nbsp;
    <a href="https://media.istockphoto.com/photos/plant-growing-picture-id510222832?k=6&m=510222832&s=612x612&w=0&h=Pzjkj2hf9IZiLAiXcgVE1FbCNFVmKzhdcT98dcHSdSk=" class="zoom">image2</a>&nbsp;
</span>
<span class="imageParent parent2">
    <a href="#" target="_blank">
        <span class="portfolio-links">
            <span class="ion-ios-arrow-right portfolio-links-icons">noimage</span> 
        </span>
    </a>&nbsp;
    <a href="https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg" class="zoom">
        <span class="portfolio-links">
            <span class="ion-arrow-expand portfolio-links-icons">image 3</span> 
        </span>
    </a>
</span>

You can also test it here .. https://jsfiddle.net/nimittshah/vgpsyado/

Without repeating same code.. https://jsfiddle.net/nimittshah/vgpsyado/8/

🌐
cdnjs
cdnjs.com › home › libraries › magnific-popup.js
magnific-popup.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
magnific-popup.js · Lightbox and modal dialog plugin. Can display inline HTML, iframes (YouTube video, Vimeo, Google Maps), or an image gallery. Animation effects are added with CSS3 transitions.
🌐
CodePen
codepen.io › ryanjbonnell › pen › DgdGXr
Open Magnific Popup Gallery from Link
$('.gallery-link').on('click', function () { $(this).next().magnificPopup('open'); }); $('.gallery').each(function () { $(this).magnificPopup({ delegate: 'a', type: 'image', gallery: { enabled: true, navigateByImgClick: true }, fixedContentPos: false }); });
🌐
Stack Overflow
stackoverflow.com › questions › 42953416 › magnific-popup-image-gallery-inside-of-modal-box
jquery - Magnific Popup – Image gallery inside of modal box - Stack Overflow
March 22, 2017 - var parentPopup = false; $.magnificPopup.open({ items: {src: '#inline-content'}, type: 'inline', callbacks: { open: function () { $('#gallery') .off('click') .on('click', function(e) { e.stopPropagation(); // If an instance is open, keep track and close it if ($.magnificPopup.instance.isOpen) { parentPopup = true; // Here we could also store the parent instance in a global var using $.magnificPopup.instance.clone() to, for example, know which was the parent popup if we have multiple of them. $.magnificPopup.close(); } }) .magnificPopup({ type: 'image', gallery: { enabled: true }, callbacks: { afterClose: function() { // If we come from a parent popup if (parentPopup === true) { // Reopen initial popup here } } } }); } } });
🌐
SoloDev
solodev.com › blog › web-design › adding-magnific-popup-to-your-photo-gallery.stml
Adding Magnific Popup to your Photo Gallery
September 28, 2016 - This tutorial shows you how to add interactivity to your photo galleries with magnific popup.
Top answer
1 of 4
12

Here is a simple solution I've used for this:

$('.image-link, .video-link').magnificPopup({
    callbacks: {
      elementParse: function(item) {
         // the class name
         if(item.el.context.className == 'video-link') {
           item.type = 'iframe';
         } else {
           item.type = 'image';
         }
      }
    },
    gallery:{enabled:true},
    type: 'image',
});

It should work with type formatters.

2 of 4
6

You are able to define the type ofa gallery item using the mfp-TYPE CSS class. So in this case you would add mfp-iframe to the anchor tag pointing to your video and the plugin will handle the rest.

HTML:

<div class="gallery">
  <!-- Image -->
  <a href="https://www.example.com/image-fullsize-1.jpg">
     <img src="https://www.example.com/image-thumbnail-1.jpg" alt="">
  </a>

  <!-- Video item with mfp-iframe class -->
  <a href="https://www.example.com/video-url" class="mfp-iframe">
     <img src="https://www.example.com/video-thumbnail.jpg" alt="">
  </a>

  <!-- Image -->
  <a href="https://www.example.com/image-fullsize-2.jpg">
     <img src="https://www.example.com/image-thumbnail-2.jpg" alt="">
  </a>

  <!-- Image -->
  <a href="https://www.example.com/image-fullsize-3.jpg">
     <img src="https://www.example.com/image-thumbnail-3.jpg" alt="">
  </a>
</div>

JS:

$('.gallery').magnificPopup(
        {
            delegate: 'a',
            type: 'image',
            tLoading: 'Loading image #%curr%...',
            mainClass: 'mfp-img-mobile',
            gallery: {
                enabled: true,
                navigateByImgClick: true,
                preload: [0,1] // Will preload 0 - before current, and 1 after the current image
            },
            image: {
                tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
                titleSrc: function(item) {
                    return '';
                }
            }
        }
    );

More information can be found in the documentation:

http://dimsemenov.com/plugins/magnific-popup/documentation.html#content-types

🌐
Drupal
drupal.org › project › magnific_popup
Magnific Popup | Drupal.org
February 13, 2024 - Activate the Magnific Popup module, then manage the display of any Image fields or video_embed_field fields. Choose "Magnific Popup" as the formatter and optionally configure Gallery Style options on the field.
🌐
concrete5
archive.concretecms.org › community › forums › 5-7-discussion › magnific-popup-as-gallery
magnific popup as gallery - concrete5
July 19, 2015 - <script type="text/javascript"> $(document).ready(function() { $('.popup-gallery').magnificPopup({ delegate: 'a', type: 'image', tLoading: 'Loading image #%curr%...', mainClass: 'mfp-img-mobile', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] // Will preload 0 - before current, and 1 after the current image }, image: { tError: '<a href="%url%">The image #%curr%</a> could not be loaded.', titleSrc: function(item) { return item.el.attr('title') + '<small>Timetrekkers</small>'; } } }); }); </script>
🌐
Simmons University
web.simmons.edu › ~grovesd › comm244 › notes › week13 › magnific › magnific
How to Use Magnific | Comm244 Notes
Magnific allows for the use of ... maybe inline types. A primary benefit of Magnific is that its modals are responsive. So, the popups will adjust to the size of the browser window....
🌐
CodePen
codepen.io › DeoThemes › pen › XgBZBB
Magnific Popup - Multiple Galleries
<!-- First Gallery --> <div ... image 1-2 (gallery #2)</span> </a> <a href="https://deothemes.com/wp-content/uploads/2017/04/A-ha-Shop_Minimal-Elegant-eCommerce-HTML-Template_preview.jpg"></a> </div> ... span { display: block; padding: 10px; font-family: sans-serif; text-decoration: none; color: #000; font-size: 20px; } .gallery { float: left; margin-right: 30px; } ... (function($){ $('.gallery').each(function() { // the containers for all your galleries $(this).magnificPopup({ delegate: ...
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 1043
Multiple Galleries · Issue #1043 · dimsemenov/Magnific-Popup
December 29, 2017 - I have several thumbs on one page, each open a separate set of images, but when the set of images is finished, the gallery picks the images from the next gallery instead of the starting at the beginning again. Previously I have simple had to assign a different ID to each of the sets, but in this case I cannot seem to find a solution. Script and HTML included below, ANY suggestion is greatly appreciated!!** <head> <script> $(document).ready(function() { $('.popup-gallery').magnificPopup({ delegate: 'a', type: 'image', tLoading: 'Loading image #%curr%...', mainClass: 'mfp-img-mobile', gallery: {
Author   vikingbeards
🌐
GitHub
github.com › dimsemenov › Magnific-Popup
GitHub - dimsemenov/Magnific-Popup: Light and responsive lightbox script with focus on performance. · GitHub
Use native <dialog> element if you need a basic dialog/modal/popup, or my PhotoSwipe library if you need an advanced image gallery. Feel free to email me if you need assistance. Fast, light and responsive lightbox plugin, for jQuery and Zepto.js. Documentation and getting started guide. Examples and plugin home page. More examples in CodePen collection. Optionally, install via Bower bower install magnific-popup or npm: npm install magnific-popup.
Starred by 11.4K users
Forked by 3.4K users
Languages   JavaScript 67.9% | HTML 18.5% | CSS 8.1% | SCSS 5.5%