14

When I downloaded the latest version 3.8.1, inside wp-include/js there is a jQuery folder.

Can I assume that WordPress will always include it, meaning I don't have to make my own call? E.g.

wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', array(), null, false); 
wp_enqueue_script('jquery'); 
2
  • 2
    Yes. Just keep in mind that jQuery is loaded in compatibility mode, so you can't use the $ shorthand notation.
    – Dan
    Apr 7, 2014 at 3:08
  • 1
    I don't see it in my recent install of WordPress 5. It's not showing in the source code.
    – Mark
    Jan 7, 2019 at 17:05

3 Answers 3

30

Yes, jQuery is part of WordPress core. But--it can become outdated, because jQuery updates can happen in between WP releases. The recent release of WordPress does use a very recent version of jQuery.

By default,

wp_enqueue_script('jquery') 

grabs jQuery from the core at /wp-includes/js/jquery/jquery.js.

The "correct" way to add jQuery to your WP site is:

function theme_scripts() {
  wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'theme_scripts');

Another catch--if you do use the latest jQuery, be careful that it doesn't break plugins.

5
  • 4
    WordPress updates jQuery usually within a couple of days of the jQuery's release itself, but only for the latest beta versions. The jQuery in the latest WordPress will never be very far behind jQuery, so it should never realistically be necessary to use a newer one.
    – Otto
    Apr 5, 2014 at 3:32
  • 3
    Always and only use the version of jQuery bundled with WordPress. Do not use a custom version in Themes or Plugins. Apr 5, 2014 at 16:07
  • I agree with the two comments above--but, the main problem with jQuery version updates is what I said above--breaking plugins. It's not a critical problem, but one to watch out for.
    – James
    Apr 6, 2014 at 3:37
  • Use google cdn.
    – ahmetlutfu
    Apr 6, 2014 at 9:39
  • It worked like charm.. Jun 11, 2019 at 17:44
5

You still need to enqueue it, but you do not need to register it, as it is registered automatically.

0

Jquery is included inside the core wordpress files but you need to load it manually for the frontend user.

for admin dashboard it was loaded automatically.

keep in mind you can't use the shorthand notation $.

you need to use jQuery instead of $

if you want to use $ instead of jQuery just put this block of code to your custom js file

var $ = jQuery.bind({});
1
  • None of this is accurate. If the OP is writing a script that requires jQuery to run, then the OP simply needs to include jQuery as a dependency when enqueuing the script. array( 'jquery' ) is all that's needed when enqueuing. developer.wordpress.org/reference/functions/wp_enqueue_script You can avoid having to use jQuery() instead of $ by starting your script file with (function( $ ) { and ending it with } )( jQuery );. Jan 16 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.