I am trying to learn WP theme development. And I just learned that WP already has a jQuery version included. Until now I have been using the jQuery from Google’s CDN.

So I just now deleted the CDN link from my code. And of course all my jQuery code stopped working.

So I guess I am missing something. What do I need to do if I want to use WordPress’s local jQuery?

When I search SE QA and Google all I can find is how to un-register the local jQuery version and then register CDN. But that is not what I want to do. I want to use the local jQuery.

So what am I missing?

2 Answers
2

WP’s jQuery is not mapped to $ like you may expect, it is loaded in noConflict mode so you’ll need to use jQuery() instead of $(), unless you map it yourself.

When you include your js file you’ll want to make sure to set jQuery as a dependency as well:

wp_enqueue_script( 'your-script-handle', get_stylesheet_directory_uri() . '/js/your-script.js', array( 'jquery' ), '1.0.0' );

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *