-
AuthorPosts
-
January 5, 2024 at 8:23 pm #1429375
Hello,
I would like to open a Pop-Up/Lightbox with text on any type of link. If I click on a Button or an a link of my portfolio grid.
Just like it would be a picture, but it’s just plain text (may with a picture inside the text block)
How can I do this?Best regards
- This topic was modified 10 months, 3 weeks ago by northorie.
January 6, 2024 at 5:29 pm #1429407Hey northorie,
To create a text box popup add this code to the end of your child theme functions.php file in Appearance ▸ Editor:function magnific_popup_with_no_scroll() { ?> <script> (function($) { $(window).on('load', function(){ $('.open-popup-link').addClass('no-scroll'); $('.open-popup-link').magnificPopup({ type:'inline', midClick: true, callbacks: { beforeOpen: function () { $('body').css("overflow-y", "hidden"); }, close: function() { $('body').css("overflow-y", "auto"); }, }, }); }); })(jQuery); </script> <?php } add_action( 'wp_footer', 'magnific_popup_with_no_scroll', 99 );
Then on the page you want the popup to show on add this into a code block:
<div id="open-popup" class="popup mfp-hide"> <p>PLACE CONTENT HERE</p> </div>
change the “PLACE CONTENT HERE” text to suit your needs, including adding a image.
Then add this CSS in your Enfold Theme Options ▸ General Styling ▸ Quick CSS field:.popup { position: relative; background: #FFF; padding: 20px; width: auto; max-width: 500px; margin: 20px auto; }
Here is an example with a image in the popup:
Best regards,
MikeJanuary 7, 2024 at 1:55 pm #1429462Thank you very much, it’s exactly what I want.
But it doesn’t work properly yet.
I placed the link inside the first box on the homepage.
The popup opens, but without the styling.Further questions:
1. How can I open this popup from a button
2. How can I make the codeblock invisible on the page? I placed it at theend, just right above the footer, but there is a free space nowBest regards
- This reply was modified 10 months, 2 weeks ago by northorie.
January 7, 2024 at 1:55 pm #1429463January 7, 2024 at 2:18 pm #1429470Hi,
As for the popup styling, it looks like I made an error in the snippet above, please change the popup code to this:<div id="open-popup" class="popup mfp-hide"> <p>PLACE CONTENT HERE</p> </div>
so the css will work correctly, I adjusted the code above.
On your page it looks like you added the code block element after the grid row, so a new section was created, this space is not the code block it self, it has a height of zero. So try adding the code block in the grid row under the contact form.
Or you can add this css:#after_grid_row_4 { display: none; }
Best regards,
MikeJanuary 7, 2024 at 2:48 pm #1429473Thank you Mike!
The space at the bottom is gone an the popup appears propely :) I’m happyLast one: how can I use the popup on a button? I want the popup/lightbox to open, when a button is clicked
- This reply was modified 10 months, 2 weeks ago by northorie.
January 7, 2024 at 3:54 pm #1429477First – Mikes post is still right – but the need for the callback function is not necessary anymore – because there is now a filter for reaching the fixed background on lightbox opened.
add_filter( 'avf_default_lightbox_no_scroll', '__return_true' );
next: the code for that inline popup is correct but you had to know that the class open-popup-link had to be the trigger for the magnificPopup function.
On button Element the custom class goes to the button wrapper – not the anchor itself. – so the selector had to reflect that ( the class is parent of the anchor)function inline_popup_every_avia_ID_you_like() { ?> <script type="text/javascript"> (function($){ $(window).on('load', function () { $('.open-popup-link').find('a').addClass('no-scroll'); $('.open-popup-link a').magnificPopup({ removalDelay: 500, type:'inline', midClick: true, }); $(document).on('click', '.popup-modal-dismiss', function (e) { $.magnificPopup.close(); }); }); })(jQuery); </script> <?php } add_action('wp_footer', 'inline_popup_every_avia_ID_you_like', 999);
summary:
- the trigger is a link which is child of the custom-class: open-popup-link
- if you got a lot of these trigger links you can give that custom-class to the color-section etc. this indicates that all links inside goes to lightbox.
- if you want to link to another lightbox from that modal window – just place a button inside again with class: open-popup-link
- there is a second class – thats for a link inside the popup that could close the lightbox: popup-modal-dismiss
nice to have for links in the lightbox that goes to an anchor link (f.e. one-pager sites). - the triggered link should have now a manual link to an anchor with unique ID
- give to this element that goes to the lightbox the class mfp-hide (to make it invisible) and maybe the class white-popup (for prestyled styling of the lightbox by magnificPopup) and the ID of the button link
January 7, 2024 at 4:16 pm #1429478Hi,
To enable a button to open the popup, add a button to your page and set the link URL to #open-popup:
then go to Advanced ▸ Developer Settings and add the custom class open-popup-button:
then update the popup script in your child theme functions.php to this:function magnific_popup_with_no_scroll_and_button() { ?> <script> (function($) { $(window).on('load', function(){ $('.open-popup-button a').addClass('open-popup-link'); $('.open-popup-link').addClass('no-scroll'); $('.open-popup-link').magnificPopup({ type:'inline', midClick: true, callbacks: { beforeOpen: function () { $('body').css("overflow-y", "hidden"); }, close: function() { $('body').css("overflow-y", "auto"); }, }, }); }); })(jQuery); </script> <?php } add_action( 'wp_footer', 'magnific_popup_with_no_scroll_and_button', 99 );
then you can use both text links and buttons for your popup like in the example:
Best regards,
MikeJanuary 7, 2024 at 5:55 pm #1429483Awesome! Thank you so much!
Now I have three buttons and each should open an own popup. I tried with a link to #open-popup2
an addes this code inside the code block<div id="open-popup2" class="popup mfp-hide"> <p>PLACE CONTENT HERE 2</p> </div>
But no popup appears. What did I do wrong?
It works on the text-link though, but not on the second button in the middle
- This reply was modified 10 months, 2 weeks ago by northorie.
January 7, 2024 at 6:26 pm #1429486Hi,
On my test page I added two more buttons with the URLs #open-popup3 and #open-popup2
and adjusted the code blocks to match:
and they work correctly:
try checking your code again.Best regards,
MikeJanuary 8, 2024 at 1:21 pm #1429553This reply has been marked as private.January 8, 2024 at 5:38 pm #1429585Hi,
It looks like you are not using the new code that I posted above that allows buttons to be used.
It also looks like you didn’t add the custom class to the buttons for the new script to work, please review this thread again.Best regards,
MikeJanuary 8, 2024 at 6:06 pm #1429588Yes! I missed that – sorry. Now i’m happy :) Thanks again
Thread can be closed.January 8, 2024 at 6:30 pm #1429592Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Pop-Up/LIghtbox’ is closed to new replies.