对,我自己弄明白了,不知道这有多“黑”,但基本上这就是代码:
public function filter_scripts_styles(){
if(is_page($this->plugin_name)){
//Same name is used for the style as the js file so can reuse this array
$allowed = array(\'jquery\', $this->plugin_name.\'_scrollpath\', $this->plugin_name);
//Check Scripts First
global $wp_scripts;
foreach($wp_scripts->queue as $handle ) {
if(!in_array($handle, $allowed)){
//echo \'Dequeuing : \'. $handle;
wp_dequeue_script($handle);
}
}
//Check styles
global $wp_styles;
foreach($wp_styles->queue as $handle ) {
if(!in_array($handle, $allowed)){
//echo \'Dequeuing : \'. $handle;
wp_dequeue_style($handle);
}
}
}
}
基本上,我添加了一个操作:
$this->loader->add_action( \'wp_print_styles\', $plugin_public, \'filter_scripts_styles\' );
如果您使用的是普通WP;
add_action(\'wp_print_styles\', \'filter_scripts_styles\');
我在页面上添加了我知道需要的东西的句柄的名称,其他所有东西都将退出队列。
希望其他人会觉得这很有用。