I have a custom js file as part of my wordpress installation, which is registered and enqueued using functions.php as normal. I have registered this particular script to load within wp_footer rather than within wp_header. However, I also have a plugin that is putting js into wp_footer, and by default it is loading this below my script. I need to force my script to load last. Is there soemthing simple that can be done to achieve this? It seems like something fairly routine to me?
Here is my code:
function scripts() {
// Register scripts
// js
wp_register_script('custom', get_bloginfo('template_url'). '/js/custom.js', false, false, true);
// Enqueue scripts
wp_enqueue_script('custom');
}
add_action('wp_enqueue_scripts', 'scripts');
The current order of the scripts goes, but I need to force my script to load after the plugin:
<script>/my_script.js</script>
<script>/plugin_script.js</script>
Thanks in advance!
Just set the
$priority
parameter to a ridiculously high value:To be the very last in the queue (though one can never be sure) use php’s
PHP_INT_MAX
constant:Edit cf. discussion in comments. Note that the following is NOT the recommended way of enqueueing scripts in the footer.