Wordpress - How can I de-register ALL styles all at once? And same with Javascript?
I hope you know what you are doing. You can use the wp_print_styles
and wp_print_scripts
action hooks and then get the global $wp_styles
and $wp_scripts
object variables in their respective hooks.
The "registered" attribute lists registered scripts and the "queue" attribute lists enqueued scripts on both of the above objects.
An example code to empty the scripts and style queue.
function pm_remove_all_scripts() {
global $wp_scripts;
$wp_scripts->queue = array();
}
add_action('wp_print_scripts', 'pm_remove_all_scripts', 100);
function pm_remove_all_styles() {
global $wp_styles;
$wp_styles->queue = array();
}
add_action('wp_print_styles', 'pm_remove_all_styles', 100);
You can also do it on a per basis by finding the handlers being called upon, search for wp_enqueue_style
or wp_enqueue_script
you can deregister them like this on your functions.php
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'some-css' );
}
add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
wp_deregister_script( 'tutorials-js' );
wp_deregister_script( 'gsc_dialog' );
wp_deregister_script( 'gsc_jquery' );
}
Hameedullah solution is better, however if you run into problems due to some scripts not loading give the above a shot.