I would like to know how to list all scripts loaded on a page, ranked by order and change this order.
1 comment
Comments are closed.
I would like to know how to list all scripts loaded on a page, ranked by order and change this order.
Comments are closed.
When you take a look at the source of
wp_enqueue_scripts()
(or the register-sister), then you’ll see that there’s theglobal $wp_scripts
handling all the heavy stuff.Basically the global is just an instance of
WP_Scripts
, which is a child ofWP_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
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 ofarray( '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”.