WordPress force scripts to load after plugins

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:

Read More
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!

Related posts

Leave a Reply

1 comment

  1. Just set the $priority parameter to a ridiculously high value:

    add_action( 'wp_enqueue_scripts', 'scripts', 999999 );
    

    To be the very last in the queue (though one can never be sure) use php’s PHP_INT_MAX constant:

    add_action( 'wp_enqueue_scripts', 'scripts', PHP_INT_MAX );
    

    Edit cf. discussion in comments. Note that the following is NOT the recommended way of enqueueing scripts in the footer.

    add_action( 'wp_print_footer_scripts', 'so26898556_print_footer_scripts', ( PHP_INT_MAX - 2 ) );
    function so26898556_print_footer_scripts()
    {
        echo '<script src="' . get_bloginfo( 'template_url' ) . '/js/custom.js"></script>';
    }