Get the list of enqueued scripts in wordpress? Get the list of enqueued scripts in wordpress? wordpress wordpress

Get the list of enqueued scripts in wordpress?


There is a dedicated Wordpress action hook for styles as well as scripts. These hooks will be triggered after every script or style is enqueued:

function inspect_scripts() {    global $wp_scripts;    print_r($wp_scripts->queue);}add_action( 'wp_print_scripts', 'inspect_scripts' );function inspect_styles() {    global $wp_styles;    print_r($wp_styles->queue);}add_action( 'wp_print_styles', 'inspect_styles' );


When I did <?php global $wp_scripts; var_dump($wp_scripts->queue); ?> on the index.php page of the standard 2014 Wordpress theme it showed me non-admin scripts that were being queued. If you just do var_dump on the $wp_scripts variable itself you'll get lots of scripts, I am guessing all the scripts in the theme or something like that.

So if you are only showing this info to the site administrator then it should be fine just to echo it out like at the bottom of the page. I used a memory profiling plugin once (it showed me load times/memory loads used by various plugins) and it put that information at the bottom of the page, it was pretty useful.

But like the comments say if you are only displaying the queued scripts then in the wp-admin area that is only the admin scripts, on the front end you'll get more.