我使用这段代码从wp_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();}
?>有人能帮我把这个修好吗?
发布于 2014-01-14 14:22:01
完全脱离任何上下文(因为问题中确实没有指定它),只在jQuery上下文中加入bbPress的正确方法是在回调的内部添加一个适当的条件,并连接到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' );https://wordpress.stackexchange.com/questions/129696
复制相似问题