
-
AuthorPosts
-
May 19, 2025 at 11:30 am #1484444
Hey @Ismael,
I found an old thread of yours and @Guenni007 and I am wondering if I could load a title for a lightbox if the lightbox contains an image from the media library?!
Example: I have a link in a text like
https://homepage.de/wp-content/uploads/image.jpg?iframe=true
to show the image in a lightbox. Everything works as expected, the lightbox opens the image from the library in an iframe. But no title, description or whatsoever.Any idea on how to get the title displayed with an
?iframe=true
link? I already tested to put text into the available fields in the media library, but there is no title below the iframe in the lightbox.All the best,
DanielMay 20, 2025 at 6:49 am #1484476Hey Daniel,
Thank you for opening another thread.
Have you tried directly adding the alt or title attribute to the element with the ?iframe=true link?
<a class="content1 mfp-iframe lightbox-added" href="https://ipg-messe.noops.de/wp-content/uploads/2025/05/01_experience_overview_screen_01-scaled.jpg?iframe=true"> <span class="dashicons dashicons-playlist-video"></span> </a>
Replace it with:
<a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="content1 mfp-iframe lightbox-added" href="https://xxxxxx.de/wp-content/uploads/xxx/xxxxx/xxxxxjpg?iframe=true"> <span class="dashicons dashicons-playlist-video"></span> </a>
Best regards,
IsmaelMay 20, 2025 at 9:19 am #1484484Hi Ismael,
nice idea! I tried it (see code) but it sadly didn’t work. The iframe lightbox has no title container at all. If I inspect the lightbox of a gallery I see a div for the title. There is no such div with an iframe lightbox …
Can I somehow get the iframe lightbox to show it?
Best regards,
DanielMay 21, 2025 at 6:18 am #1484514Hi,
Thank you for the update. We deleted the URL from the previous post.
Try to replace the html with:
<a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="content1 inline_popup" href="IFRAME URL HERE" > <span class="dashicons dashicons-playlist-video"></span> </a>
Add this code in the functions.php file:
function av_inline_popup_enabler() { ?> <script> (function($){ $(document).ready(function() { $('.inline_popup').magnificPopup({ type: 'iframe', midClick: true, callbacks: { open: function() { var title = this.st.el.attr('title') || this.st.el.attr('alt') || ''; if (title) { var $caption = $('<div class="mfp-title" style="text-align:center; padding:10px 0;">' + title + '</div>'); this.contentContainer.append($caption); } } } }); }); })(jQuery); </script> <?php } add_action('wp_footer', 'av_inline_popup_enabler', 9999);
Then insert this css code in the Quick CSS field:
div .mfp-title { z-index: 9999; position: relative; color: #ffffff; bottom: -50px; }
Best regards,
IsmaelMay 21, 2025 at 4:18 pm #1484531Nice! Thank you Ismael, now I can load the title. But: The connection to the next images is broken! I have more pictures, connected as lightbox gallery like that:
<div class="isotope"> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="xxx.img??iframe=true"> 01 </a> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="xxx.img??iframe=true"> 02 </a> </div>
With your code only the first image loads in a lightbox. The arrows to navigate from 01 to 02 are missing.
Can you fix that?
All the best,
DanielMay 22, 2025 at 6:59 am #1484556Hi,
We just noticed that you’re trying to load jpg images. What happens when you remove the iframe=true parameter completely? Make sure that link contains the “lightbox” class name.
<div class="isotope"> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="lightbox" href="xxx.jpg"> 01 </a> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="lightbox" href="xxx.jpg"> 02 </a></div>
The title or alt attribute should automatically display without the custom script.
Best regards,
IsmaelMay 22, 2025 at 10:04 am #1484577Hi Ismael,
this works! But: For images only. I use the iframe=true for mixing images and videos. Should have made that clearer:
<div class="isotope"> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="xxx.img?iframe=true"> 01 </a> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="xxx.mp4?iframe=true"> 02 </a> </div>
So I am back to your script because it works for images and videos but breaks the possibility to click from 01 to 02 – any idea on how to keep the arrows linking to the next frame working?
Best regards,
DanielMay 23, 2025 at 6:45 am #1484595Hi,
Please replace the script with this:
function av_inline_popup_enabler() { ?> <script> (function($){ $(document).ready(function() { $('[class*="group-"]').each(function() { $(this).magnificPopup({ delegate: 'a.inline_popup', type: 'image', gallery: { enabled: true }, midClick: true, callbacks: { elementParse: function(item) { var href = item.el.attr('href'); if (href.match(/\.(jpg|jpeg|png|gif|webp)(\?.*)?$/i)) { item.type = 'image'; } else { item.type = 'iframe'; } }, open: function() { var title = this.st.el.attr('title') || this.st.el.attr('alt') || ''; if (title) { var $caption = $('<div class="mfp-title" style="text-align:center; padding:10px 0;">' + title + '</div>'); this.contentContainer.append($caption); } } } }); }); }); })(jQuery); </script> <?php } add_action('wp_footer', 'av_inline_popup_enabler', 9999);
This will group the items based on the parent container (group-1, group-2) and also parse the element format and return the correct type, so you don’t need to add the iframe parameter to images.
<div class="group-1"> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="image.jpeg" title="Image 1">Image 1</a> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="video.mp4?iframe=true" title="Video 1">Image 2</a></div> <div class="group-2"> <a alt="CUSTOM ALT HERE" title="CUSTOM TITLE HERE" class="inline_popup" href="image.png" title="Image">Image</a></div>
Best regards,
IsmaelMay 26, 2025 at 11:40 am #1484673Hi Ismael,
it still is not working as expected. Now the arrows are back, I can go from one slide to the other, even with mixed media (image / video). But it is missing the title for videos. Can I somehow show titles for images and videos?
And: It would be fine for me to add ?iframe=true to all linked media, in fact it would be easier this way. But I am finde with whatever fits your solution.
Quick note: You specified the title twice in you HTML.
Best regards,
DanielMay 26, 2025 at 1:35 pm #1484682Hi,
Looks like it’s not possible to display a title when displaying an iframe or video in the magnific popup or lightbox. We tried the solution in the following thread, but it is still not working.
— https://stackoverflow.com/questions/17612258/title-for-iframe-video-in-magnific-popup
Best regards,
IsmaelMay 26, 2025 at 2:47 pm #1484684Hi Ismael,
thanks for your link. This works: https://codepen.io/dimsemenov/pen/kXGxJv
But: The arrows ar missing again. We are one big step further and have JPG and MP4 with captions and opening in lightboxes. How can I have them grouped with arrows to go from one to the next?
<div class="isotope"> <a class="test" title="Test title1" href="xxx.mp4?iframe=true">Vid1</a> <a class="test" title="Test title2" href="xxx.mp4?iframe=true">Vid2</a> <a class="test" title="Test title3" href="xxx.jpg?iframe=true">Img1</a> </div>
Script:
(function($){ $(document).ready(function() { $('.test').magnificPopup({ type: 'iframe', iframe: { markup: '<div class="mfp-iframe-scaler">'+ '<div class="mfp-close"></div>'+ '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+ '<div class="mfp-title">Some caption</div>'+ '</div>' }, callbacks: { markupParse: function(template, values, item) { values.title = item.el.attr('title'); } } }); }); })(jQuery);
Do you have an idea how to merge the lightboxes as you have done with your script before?
Kind regards,
DanielMay 26, 2025 at 2:50 pm #1484685Maybe it is sufficient to add:
gallery: { enabled: true }
Could that be possible?
-
This reply was modified 2 weeks, 6 days ago by
spooniverse.
May 28, 2025 at 9:03 am #1484762Hi Ismael,
I tried to add the gallery function like that:
(function($){ $(document).ready(function() { $('.test').magnificPopup({ type: 'iframe', gallery: { enabled: true }, iframe: { markup: '<div class="mfp-iframe-scaler">'+ '<div class="mfp-close"></div>'+ '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+ '<div class="mfp-title">Some caption</div>'+ '</div>' }, callbacks: { markupParse: function(template, values, item) { values.title = item.el.attr('title'); } } }); }); })(jQuery);
And it works! Images and videos mixed in a lightbox gallery as iframes with titles below each entry. Only the arrows look different to the usual ones from the lightbox, but I can sort that out with CSS I think.
Thank you for helping me out!
All the best,
DanielMay 29, 2025 at 2:31 am #1484810 -
This reply was modified 2 weeks, 6 days ago by
-
AuthorPosts
- The topic ‘Show caption in iframe lightbox’ is closed to new replies.