When you develop a WordPress plugin or theme, you might want to make use of the jQuery library included and distributed with the WordPress package.
So, first off, fire the wp_enqueue_script function in order to safely reference your jQuery library to ensure that the jQuery core is available for usage with your plugin or theme. Other plugins might fire this function with the same handle in order to use jQuery, but you don’t know this and you aren’t sure what other plugins your users will be using, so you have to be sure that it is included.
<?php wp_enqueue_script('jquery'); ?>
Ultimately, WordPress will insert a <script> tag into the <head> section of the page referencing the jQuery library by including the “jquery.js” source file.
Next thing to do is prevent conflicts between libraries. By default, jQuery is used with a global variable which is a dollar sign. See the example below which shows (makes visible) an element on the page with the ID “mydiv”.
With that done, you can now use this object instead and be confident that there won’t be any conflicts between the jQuery library and other libraries inside WordPress. Below is the modified code for making the element with the ID “mydiv” visible as shown earlier.
I hope this helps! Best of luck and feel free to post your comments!