Hey @narhanju,
You might want to make sure your code works using Daniel’s instructions first before porting it into your theme. And, you should also follow WordPress standards for enqueueing JS.
Here’s what I suggest:
1) In your HTML, wrap your image with an <a href=""></>
tag that has the link to your download in the href
property.
2) Make sure you add a
to your click trigger CSS selector. E.g., .popmake-244319 a
.
3) Remove your script from your index.php
. Add it to your functions.php
or use a 3rd-party plugin (like in the video). Here’s an example of what I have working on my test site using Popup Maker, Gravity Forms, and Code Snippets following Daniel’s video.
/**
* Add custom JavaScript for Popup Maker to the footer of your site.
*/
function gf_download_test() { ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
const popupID = 662, // Popup that launches my GF form.
hiddenFieldSelector = '#input_1_3'; // Hidden field ID in the GF form.
$(document).on('pumBeforeOpen', '#pum-'+popupID, function () {
const trigger = $.fn.popmake.last_open_trigger[0], // Link that was clicked to launch the popup.
field = $(hiddenFieldSelector);
console.log(<code>[PUM] field:</code>);
console.log(field); // Sanity check.
if (trigger && "" !== trigger.href) {
console.log(<code>[PUM] trigger.href: ${trigger.href}</code>); // Sanity check
field.val(trigger.href);
} // if
});
});
</script><?php
}
add_action( 'wp_footer', 'gf_download_test', 500 );
/**
* Add the code above to your child theme's functions.php file or
* use a code snippets plugin.
*/
P.S. Please note in the code above, WordPress might substitute my string literals (backticks) in the console.logs()
with <code></code>
. I can post the code on GitHub if that’s better for you. Just let me know ??
-
This reply was modified 3 years, 4 months ago by
mark l chaves. Reason: Note about unwanted code replacements
-
This reply was modified 3 years, 4 months ago by
mark l chaves.
-
This reply was modified 3 years, 4 months ago by
mark l chaves.