Does wordpress load jQuery by default?

jQuery(document).ready(function($){
   alert("Hi");
});

I want to add jQuery script written above to WordPress site in body section, now my question is whether WordPress loads jQuery library by default or I need to add <?php wp_enqueue_script('jquery'); ?> above the script?

We usually add <?php wp_enqueue_script('jquery'); ?> while developing wordpress plugins but is the same enqueue script required while adding jQuery script manually in wordpress? (I am not intended to create WP plugin but just want to add jQuery code in WordPress site)

Related posts

Leave a Reply

3 comments

  1. Got the answer for my own question after some research.. Though WordPress comes with built-in jQuery, it doesn’t load jQuery library by default, we need to add wp_enqueue_script('jquery'); in functions.php

  2. Themes have the option of loading jQuery. One thing is that some themes use their own version of jQuery (as to avoid issues when WordPress updates and updates jQuery versions). The admin section of jQuery usually always includes it.

    If you can, try to write jQuery that is cross-version compatible (if you want lots of sites to use your plugin).

    To directly answer your question, you are best to add your own enqueue_script jquery…it doesn’t hurt to have multiple calls to enqueue jquery.

  3. One more step before wp_enqueue_script to the .php file you need to register the .js (JQuery) file using wp_register_script() the source path constant location.