0

I just installed a fresh WP 5.6 and I realized that there is no JQuery at all inside the blog (it is still inside wp-includes/jq/jquery, but it is not loaded by default: jQuery or $ return undefined function.

Has JQuery been removed by default from WP ?

I am trying to develop a WP plugin that uses Jquery (ajax calls): Should I manually load JQuery with wp_enqueue_scripts ?

add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
   function my_jquery_enqueue() {
      wp_enqueue_script('jquery');
    }
1
  • 1
    jQuery was never loaded by default. It was only loaded if it was needed by a theme or plugin. If you are not using one that does, which is increasingly likely these days, then it won’t be loaded. – Jacob Peattie Feb 27 at 10:34
1

You can ensure that jQuery is loaded by adding it to the $dependencies array when you enqueue your script.

add_action( 'wp_enqueue_scripts', 'wpse384152_enqueue_my_scripts' );
function wpse384152_enqueue_my_scripts() {
    wp_enqueue_script( 'my-script', '/path/to/my/script.js', array( 'jquery' ) );
}

That will ensure that a) jQuery gets loaded and b) it gets loaded before your script.

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.