Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the list of enqueued scripts in wordpress?

Tags:

list

wordpress

I would like to know how to get the list of scripts enqueued in wordpress via wp_enqueue_script. I have done some research and checked the wp core itself but the closest I can get is something like:

add_options_page('Wp Sysinfo', 'Wp Sysinfo', 'manage_options', 'wp-sysinfo', 'sysinfo_page');

function sysinfo_page(){
    global $wp_scripts;
    print_r($wp_scripts->queue);
}

However it only show scripts in the admin pages not the front end.

FYI: Im building a plugin to display system information in wordpress. This is to provide plugin/theme authors useful info to troubleshoot problems reported by users.

Edit:

In short, I need a way to get all scripts and styles enqueued in both admin and frontend, and view them within a custom admin page.

like image 552
kosinix Avatar asked Mar 02 '13 00:03

kosinix


1 Answers

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' );
like image 148
Alexander Heimbuch Avatar answered Sep 30 '22 14:09

Alexander Heimbuch