Last active
June 9, 2022 08:42
-
-
Save marklchaves/49fcb165484053efa3916d97d911cd47 to your computer and use it in GitHub Desktop.
Send a link to a popup and use that link in the popup as a button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Ignore this first line when copying to your child theme's functions.php file. | |
/** | |
* Based on https://youtu.be/zml-xz78o2Q | |
*/ | |
function send_link_to_popup() { ?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function ($) { | |
const popupID = 1728, // Change to your popup IDs. | |
sel = '#my-button'; // Change to your button's CSS selector. Can also be '#my-button > a' if needed. | |
$(document).on('pumBeforeOpen', `#pum-${popupID}`, function () { | |
const trigger = $.fn.popmake.last_open_trigger[0].firstChild, // Grab the popup trigger's link element. | |
link = trigger.href, // Grab the href attribute from the trigger. | |
btnLink = $(sel); // Grab the button in the popup. | |
// If the link has something, inject it into the button's link. | |
if (link && "" !== link) { | |
btnLink.attr('href', link); | |
} // if | |
}); // listener | |
}); // jQuery | |
</script> | |
<?php } | |
add_action( 'wp_footer', 'send_link_to_popup', 500 ); // Load the script in the footer with a "late" priority. | |
/** | |
* You can add the PHP code snippet to your child theme's functions.php file | |
* or with third-party plugins such as My Custom Functions and Code Snippets. | |
* | |
* Learn more: | |
* - https://docs.wppopupmaker.com/article/84-getting-started-with-custom-js | |
* - https://docs.wppopupmaker.com/article/552-getting-started-with-custom-php | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment