首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress -如果is_bbPress()注册jquery

wordpress -如果is_bbPress()注册jquery
EN

Stack Overflow用户
提问于 2014-01-14 19:47:17
回答 1查看 142关注 0票数 0

我使用以下代码从wp_head()注销jquery:

代码语言:javascript
复制
<?php if ( !is_admin() ) wp_deregister_script('jquery'); wp_head(); ?>

我想当用户在bbpress页面上添加jquery时,但它不工作:

代码语言:javascript
复制
<?php
    if (is_bbPress()) (wp_register_script('jquery'); wp_head();}
    else (!is_admin()) (wp_deregister_script('jquery'); wp_head();}
?>

有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2014-01-14 21:07:57

将脚本和样式入队的正确方法是使用wp_enqueue_script

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

所以,举个例子:

代码语言:javascript
复制
function my_enqueue_script() {
    if ( is_bbPress() ) {

        // The name used as a handle for the script
        $handle = 'script-name';

        // The url to the script
        $src = get_template_directory_uri() . '/js/example.js';

        // Array of the handles of all the registered scripts that must be loaded before this script
        $deps = array(); 

        // The version number of the script (if it has one)
        $ver = '1.0.0';

        // Should the script be placed in the document footer or the head?
        $in_footer = true;

        wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
    }
}

add_action( 'wp_enqueue_scripts', 'my_enqueue_script' );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21112794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档