我使用以下代码从wp\\u head()注销jquery:
<?php if ( !is_admin() ) wp_deregister_script(\'jquery\'); wp_head(); ?>
我希望用户在bbpress页面上添加jquery,但它不起作用:
<?php
if (is_bbPress()) {wp_register_script(\'jquery\'); wp_head();}
else (!is_admin()) {wp_deregister_script(\'jquery\'); wp_head();}
?>
谁能帮我修一下这个吗
最合适的回答,由SO网友:Chip Bennett 整理而成
完全脱离任何上下文(因为问题中确实没有指定),只有在bbPress上下文中才能将jQuery排队的正确方法是在回调中添加适当的条件,并连接到wp_enqueue_scripts
. 例如,将在中定义以下内容functions.php
(即模板或模板零件文件中的非):
function wpse129696_enqueue_scripts() {
// Only enqueue jQuery in the context of bbPress
if ( is_bbpress() ) {
wp_enqueue_script( \'jquery\' );
}
}
add_action( \'wp_enqueue_scripts\', \'wpse129696_enqueue_scripts\' );