我尝试了以下方法从家庭中删除此插件的资源,但没有一个起作用:
function dequeue_unnecessary_styles() {
wp_dequeue_style( 'crayon' );
wp_deregister_style( 'crayon' );
}
add_action( 'wp_print_styles', 'dequeue_unnecessary_styles');
function dequeue_unnecessary_scripts() {
wp_dequeue_script( 'crayon_js' );
wp_deregister_script( 'crayon_js' );
}
add_action( 'wp_print_scripts', 'dequeue_unnecessary_scripts');
我也尝试过:
remove_action('wp_head', 'crayon', 7);
remove_action('wp_head', 'crayon_js', 7);
remove_action('wp_footer', 'crayon', 7);
remove_action('wp_footer', 'crayon_js', 7)
我已经仔细研究了插件代码,并发现资源负载是通过这种方式实现的:
public static function enqueue_resources() {
if (!self::$enqueued) {
CrayonLog::debug('enqueue');
global $CRAYON_VERSION;
CrayonSettingsWP::load_settings(TRUE);
if (CRAYON_MINIFY) {
wp_enqueue_style('crayon', plugins_url(CRAYON_STYLE_MIN, __FILE__), array(), $CRAYON_VERSION);
wp_enqueue_script('crayon_js', plugins_url(CRAYON_JS_MIN, __FILE__), array('jquery'), $CRAYON_VERSION, CrayonGlobalSettings::val(CrayonSettings::DELAY_LOAD_JS));
} else {
wp_enqueue_style('crayon_style', plugins_url(CRAYON_STYLE, __FILE__), array(), $CRAYON_VERSION);
wp_enqueue_style('crayon_global_style', plugins_url(CRAYON_STYLE_GLOBAL, __FILE__), array(), $CRAYON_VERSION);
wp_enqueue_script('crayon_util_js', plugins_url(CRAYON_JS_UTIL, __FILE__), array('jquery'), $CRAYON_VERSION);
CrayonSettingsWP::other_scripts();
}
CrayonSettingsWP::init_js_settings();
self::$enqueued = TRUE;
}
}
但是在任何情况下我都没有设法消除资源,它们总是被加载。有人能看到问题吗?