我修改了Heinrich Hold answer,这样可以帮助那些希望删除、取消和取消注册主题样式和脚本的新用户。以下函数将删除所有注册的样式。
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 );
但假设您不想删除自定义样式或脚本,然后执行以下操作
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 );
希望这能帮助别人!