What’s occurring right here is your echo
is executing earlier than the rest.
Attempt utilizing the wp_enqueue_scripts
hook as an alternative of wp_footer
, and as an alternative of echo
you’ll wp_enqueue_script()
.
<?php
// Utilizing a distinct hook:
add_action( 'wp_enqueue_scripts', 'wpse_411187_script' );
operate wpse_411187_script() {
wp_enqueue_script(
// "Deal with" - a novel title to your script
'xyz-footer-print',
// Path to the JS file - modify as wanted
plugins_url( 'construct/xyz-footer-print.js', dirname( __DIR__ ) ),
// Array of dependencies
'',
// Model quantity
'1.0',
// True to position the script the footer
true
);
}
?>