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.
The jQuery library is located inside the “wp-includes/js/jquery/” folder. Even though you know what the location of the jQuery library is, I do not recommend that you reference this script using a
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.
Ultimately, WordPress will insert a
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!