How to correctly add jQuery to your WordPress Theme

August 12, 2016

If you want to extend some of the capacities of your Themes, you’ll need to add jQuery to it. Below is a quick snippet on how to do it properly.

if (!is_admin()) add_action("wp_enqueue_scripts", "jquery_enqueue", 11);
function jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}

You can extend your reading on how to properly Enqueue Scripts in WordPress by following this documentation.