Beginner's Guide for WordPress / Start your WordPress Blog in minutes

What is: jQuery

jQuery is an open source JavaScript library which is designed to provide easy client side scripting for HTML (See: JavaScript). It works on all major browsers.

In modern web design, jQuery plays an important role in adding client side scripting to web pages. jQuery is widely used to perform various tasks on the client’s browser saving bandwidth and providing a better user experience.

Some example use cases of jQuery include: sliders, lightbox popups, rotating testimonials, etc.

Using jQuery, developers can perform certain actions right in the browser without reloading a page. Some of these actions include navigating a web page, selecting elements on a page to perform actions on them, call Ajax scripts, and handle events like what happens when a user clicks an element.

WordPress comes bundled with jQuery and some essential jQuery libraries. WordPress theme and plugin developers can easily call jQuery in their own plugins and themes to add their own jQuery scripts.

To call jQuery in WordPress theme or plugin, users need to add their own jQuery scripts and enqueue them in WordPress. While enqueuing their scripts, users can call jQuery core or any jQuery plugin that comes with WordPress as a dependency. WordPress automatically loads it along with the user script.

Here is an example code. This code adds a custom javascript and calls jQuery as its dependency.

<?php
wp_enqueue_script('custom-script', get_stylesheet_directory_uri() . '/js/custom_script.js', array( 'jquery' ));
?>

Additional Reading

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!