wordpress 中的出队功能不起作用
dequeue function in wordpress is not working
我正在尝试从 wordpress 中的非相关页面中取出一些脚本。它适用于某些插件(如 contact-form-7),但不适用于其他插件。这些 .js 和 .css 文件尽管已出队,但仍在加载中,是否有任何原因?
下面的代码是通过子主题中的 functions.php 加载的。相关插件是 woo-variation-swatches.
add_action( 'wp_enqueue_scripts', 'custom_swatches_script_conditional_loading' );
function custom_swatches_script_conditional_loading(){
// Edit page IDs here
if(! is_page(39341) )
{
wp_dequeue_style('woo-variation-swatches'); // Dequeue CSS file.
wp_dequeue_style('woo-variation-swatches-theme-override'); // Dequeue CSS file.
wp_dequeue_style('woo-variation-swatches-tooltip'); // Dequeue CSS file.
wp_dequeue_script('woo-variation-swatches'); // Dequeue JS Script file.
}
}
您想像 wp_print_styles
一样在 wp_enqueue_scripts
之后挂钩它,或者只是尝试设置 add_action
.
的优先级
查看插件源代码。它将优先级为 15 的脚本排入队列。
woo-变体-swatches.php 第 103 行。
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 15 );
所以真的,任何高于 15 的优先级都应该像这样出队:
add_action( 'wp_enqueue_scripts', 'custom_swatches_script_conditional_loading', 99 );
我正在尝试从 wordpress 中的非相关页面中取出一些脚本。它适用于某些插件(如 contact-form-7),但不适用于其他插件。这些 .js 和 .css 文件尽管已出队,但仍在加载中,是否有任何原因?
下面的代码是通过子主题中的 functions.php 加载的。相关插件是 woo-variation-swatches.
add_action( 'wp_enqueue_scripts', 'custom_swatches_script_conditional_loading' );
function custom_swatches_script_conditional_loading(){
// Edit page IDs here
if(! is_page(39341) )
{
wp_dequeue_style('woo-variation-swatches'); // Dequeue CSS file.
wp_dequeue_style('woo-variation-swatches-theme-override'); // Dequeue CSS file.
wp_dequeue_style('woo-variation-swatches-tooltip'); // Dequeue CSS file.
wp_dequeue_script('woo-variation-swatches'); // Dequeue JS Script file.
}
}
您想像 wp_print_styles
一样在 wp_enqueue_scripts
之后挂钩它,或者只是尝试设置 add_action
.
查看插件源代码。它将优先级为 15 的脚本排入队列。
woo-变体-swatches.php 第 103 行。
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 15 );
所以真的,任何高于 15 的优先级都应该像这样出队:
add_action( 'wp_enqueue_scripts', 'custom_swatches_script_conditional_loading', 99 );