这就是我到目前为止所做的,如果有更好的方法我还不知道,我不会把它标记为正确答案。
add_action(\'wp_enqueue_scripts\',array( $this, \'remove_all_actions\'), 99);
public function remove_all_actions(){
if( \'custom-template.php\' != get_page_template_slug( get_queried_object_id() ))
return;
global $wp_scripts, $wp_styles;
$exceptions = array(
\'admin-bar\',
\'jquery\',
\'query-monitor\'
);
foreach( $wp_scripts->queue as $handle ){
if( in_array($handle, $exceptions))
continue;
wp_dequeue_script($handle);
}
foreach( $wp_styles->queue as $handle ){
if( in_array($handle, $exceptions) )
continue;
wp_dequeue_style($handle);
}
// Now remove actions
$action_exceptions = array(
\'wp_print_footer_scripts\',
\'wp_admin_bar_render\',
);
// No core action in header
remove_all_actions(\'wp_header\');
global $wp_filter;
foreach( $wp_filter[\'wp_footer\'] as $priority => $handle ){
if( in_array( key($handle), $action_exceptions ) )
continue;
unset( $wp_filter[\'wp_footer\'][$priority] );
}
}