开发者

How do you install jQuery in Wordpress?

How can 开发者_如何学JAVAI install jQuery on my Wordpress site?


Though one of the Answer is already Accepted but I feel the following technique may help somebody.

Include the following code at Plugin Page OR at function.php

function include_jQuery() {
    if (!is_admin()) {
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'include_jQuery');

Definitely you can use any meaningful function name instead off include_jQuery.

Alternately, you can use the following code:

function include_jQuery() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery'); 
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3'); 
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'include_jQuery');

Finally, as a general rule, you should not use the $ variable for jQuery unless you have used one of the shortcuts. The following is an example of how to shortcut jQuery to safely use the $ variable:

jQuery(function ($) {
    /* You can safely use $ in this code block to reference jQuery */
});

You may like THIS link as well from where I personally learn the above technique(s). A Very BIG Thanks to Ericm Martin!


Jquery Already packaged with the Wordpress installation, and gets available with it. Check the source code when you get your new Wordpress Blog installed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜