Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 214
Shrinivas Naik Avatar asked Sep 13 '13 15:09

Shrinivas Naik


People also ask

How to use jQuery in WordPress plugins?

As we found out, WordPress comes with jQuery. To use it in your plugins and themes properly, you need to add the following code to the functions.php file: The trick here is that by default the copy of jQuery works in a compatibility mode. This means that the well-known shortcut $ will not work.

How to load jQuery library in WordPress theme?

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 Show activity on this post. Themes have the option of loading jQuery.

What happened to jQuery-migrate in WordPress?

WordPress used to use a script called jQuery-migrate to provide backup compatibility with older versions of jQuery. However, since WordPress 5.5 this script has been retired from WordPress. If you want to add back the jQuery-migrate script or troubleshoot between different jQuery versions, then you can try the following method.

What version of jQuery is used in WordPress?

The recent release of WordPress does use a very recent version of jQuery. grabs jQuery from the core at /wp-includes/js/jquery/jquery.js. Another catch--if you do use the latest jQuery, be careful that it doesn't break plugins.


2 Answers

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

like image 136
Shrinivas Naik Avatar answered Nov 07 '22 12:11

Shrinivas Naik


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.

like image 20
Adam Erstelle Avatar answered Nov 07 '22 10:11

Adam Erstelle