I modified Heinrich Held answer so this will help new people who are looking to remove, deque and de register theme styles and scripts. The following function will remove all the styles registered.
function remove_all_theme_styles() {
if ( is_page_template('trading-dashboard.php') ) {
global $wp_styles,$wp_scripts;
foreach( $wp_styles->queue as $style ) :
$handle = $wp_styles->registered[$style]->handle;
wp_deregister_style($handle);
wp_dequeue_style($handle);
endforeach;
foreach( $wp_scripts->queue as $script ) :
$handle = $wp_scripts->registered[$script]->handle;
wp_dequeue_script($handle);
wp_deregister_script($handle);
endforeach;
}
}
add_action( 'wp_enqueue_scripts', 'remove_all_theme_styles', 100 );
But let's say you don't want to remove your custom style or script then do something like this
function remove_all_theme_styles() {
if ( is_page_template('trading-dashboard.php') ) {
global $wp_styles,$wp_scripts;
foreach( $wp_styles->queue as $style ) :
if ($wp_styles->registered[$style]->handle != 'my-custom-style') {
$handle = $wp_styles->registered[$style]->handle;
wp_deregister_style($handle);
wp_dequeue_style($handle);
}
endforeach;
foreach( $wp_scripts->queue as $script ) :
if ($wp_scripts->registered[$script]->handle != 'my-custom-script') {
$handle = $wp_scripts->registered[$script]->handle;
wp_dequeue_script($handle);
wp_deregister_script($handle);
}
endforeach;
}
}
add_action( 'wp_enqueue_scripts', 'remove_all_theme_styles', 100 );
Hope this will help someone!