Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Last active June 20, 2022 18:40
Show Gist options
  • Save marklchaves/d8b832fb0299f2a496f580a4bf81c6d8 to your computer and use it in GitHub Desktop.
Save marklchaves/d8b832fb0299f2a496f580a4bf81c6d8 to your computer and use it in GitHub Desktop.
Add document.url as a hidden field
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_action( 'wp_footer', function () { ?>
<script>
(function() {
if (document.title !== "Test Form – Avada Lab") return; // Run this script on the test form page only.
try {
document.querySelector("#doc-url").setAttribute("value", document.URL);
} catch (e) {
console.log("Something wrong happened when setting the hidden doc-url value.");
}
})();
</script>
<?php } );
/**
* Add to your child theme's functions.php file, use a code snippets plugin, or your theme's custom code settings.
*/
@marklchaves
Copy link
Author

If you need to load your function very late on the page (i.e., after modals or popups), then change line 16 to this.

<?php }, 500 );

Increase 500 all the way up to 900 as needed. The higher the number the lower down in your page your code will load.

This isn't a guarantee since some plugins and themes are greedy and want to be the very last thing loaded (to override everything else).

If that's the case, you might need to wrap the JS in setTimeout() to delay the load even longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment