首先:do not de-register core-bundled scripts in order to register some arbitrary version of those scripts.
WordPress目前(在撰写本文时)与jQuery 1.7.1捆绑在一起。当WordPress 3.4下个月发布时,该版本将是(IIRC)1.8。x、 Core、Themes和其他插件都理所当然地希望使用核心捆绑版的jQueryno-conflict mode, 注册任意版本的脚本时,这可能不是真的。因此,您将引入更多潜在的脚本破坏。
第二个:to override a script de-register/enqueue in a Plugin, you need to hook into the same action, and utilize hook priority.
假设插件回调unction thethe_image_slider_head_scripts() {}
正在使用默认优先级,10
, 然后您自己的回调需要使用lower 优先级(即ahigher number), 例如11
, 像这样:
<?php
function wpse48638_enqueue_scripts() {
// Theme script enqueues go here
}
add_action( \'wp_enqueue_scripts\', \'wpse48638_enqueue_scripts\', 11 );
?>
或者,您可以从操作中删除插件回调,然后按照常规将自己的脚本排队。注:该
remove_action()
调用必须使用
same priority 作为插件
add_action()
电话:
<?php
remove_action( \'wp_enqueue_scripts\', \'thethe_image_slider_head_scripts\' );
?>
(请注意,在这两种情况下,您都需要引用插件正在使用的相同操作
wp_head
甚至
init
, 而不是
wp_enqueue_scripts
.)
根据此评论编辑:
让我看看,当我搜索函数时:the\\u image\\u slider\\u head\\u scriptsadd_action(\'wp_print_scripts\', "thethe_image_slider_head_scripts");
这正是我们需要的!
如果您只是想删除插件的脚本排队,只需调用:
<?php
remove_action( \'wp_print_scripts\', \'thethe_image_slider_head_scripts\' );
?>
你必须使用相同的
priority 作为
add_action()
调用,因此请确保将其保留为默认值(
10
).
编辑2所以,根据抄本中的这一点智慧,你可能还需要做一件事:
还值得注意的是,您可能需要优先考虑在添加操作后将操作移除到挂钩。在添加操作之前,无法成功删除该操作。
Note: I had to download the Plugin, which required a free "club" membership from the developer, to find this solution. Seeing the full code is imperative to answering these sorts of questions.
这个
add_action( \'wp_print_scripts\', \'thethe_image_slider_head_scripts\' )
函数从另一个回调中调用,该回调本身连接到
init
. 这就是为什么你
remove_action()
调用失败:因为它是在较早的操作中启动的,而您试图删除的操作尚未添加。所以,你需要
wrap your remove_action()
call inside of a callback also hooked into init
, 像这样:
<?php
function wpse48638_init_functions() {
// Remove TheThe Image Slider scripts
remove_action( \'wp_print_scripts\', \'thethe_image_slider_head_scripts\' );
}
add_action( \'init\', \'wpse48638_init_functions\' );
?>
还请注意,您可能还需要重新排队
\'slider-ui\'
作为要删除的回调的一部分的脚本。