7

I would like to know how to list all scripts loaded on a page, ranked by order and change this order.

1

1 Answer 1

8

When you take a look at the source of wp_enqueue_scripts() (or the register-sister), then you'll see that there's the global $wp_scripts handling all the heavy stuff.

Basically the global is just an instance of WP_Scripts, which is a child of WP_Dependency and you can use all the magic from there if there's no higher level API available.

To see all registered, enqueued, etc. scripts, simply

var_dump( $GLOBALS['wp_scripts']->registered );

or do the same with enqueue. Luckily you got one argument to actually sort your stuff: dependencies. So if you want to be one script loaded after jQuery has been loaded, simply add a dependency of array( 'jquery' ) when registering or enqueueing your script. That's the way you order them in WordPress: Make them dependent on each other. Btw, the dependency name always simply is the name it was registered with, called the "handle".

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.