Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you install jQuery in Wordpress?

How can I install jQuery on my Wordpress site?

like image 740
johan Avatar asked Feb 03 '26 13:02

johan


2 Answers

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!

like image 66
enam Avatar answered Feb 06 '26 07:02

enam


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

like image 39
Django Anonymous Avatar answered Feb 06 '26 06:02

Django Anonymous



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!