0

I use this code:

if ( ! function_exists( 'WPScripts_enqueue' ) ) {
    function WPScripts_enqueue() {

        // Removing default jQuery
        wp_deregister_script( 'jquery' );

        // Enqueue the new jQuery
        wp_enqueue_script('jquery', 'https://code.jquery.com/jquery-3.2.1.slim.min.js', false, '3.2.1', false);

        // Enqueue custom Bootstrap file
        wp_enqueue_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.css', array(), false, 'all');

    }
}
add_action('wp_enqueue_scripts', 'WPScripts_enqueue');

however, wp still load jquery from wp core:

https://developers.google.com/speed/pagespeed/insights/?hl=TR&url=http%3A%2F%2Fwww.migrate2.deniz-tasarim.site%2Fhomepage%2F&tab=desktop

https://i.ibb.co/qxhCY6R/image.png

2

4 Answers 4

1

Use the Following sequence to override jquery
Install latest jQuery version 3.4.1. Update the following sequence of code and try!!!!

      wp_deregister_script('jquery');
      wp_register_script('jquery',("https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"), 
   false);
      wp_enqueue_script('jquery');

I hope it will help you!!!

0

Add priority to add_action.

add_action('wp_enqueue_scripts', 'WPScripts_enqueue', 999);

Or

add_action('wp_enqueue_scripts', 'WPScripts_enqueue', -1);
1
  • it doesnt work.
    – ahmet kaya
    Feb 14, 2020 at 15:24
0

Second documentation example (https://developer.wordpress.org/reference/functions/wp_dequeue_script/), use hook wp_print_scripts with priority 100. Like this:

function wpdocs_dequeue_script() {
    wp_dequeue_script( 'jquery-ui-core' );
}

add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );
-1

You have to first dequeue the script first & then deregister the script as given as bellow

           wp_dequeue_script( 'jquery');

           wp_deregister_script(‘jquery’);

Try this!!

2
  • it doesnt work.it is still same
    – ahmet kaya
    Feb 13, 2020 at 19:09
  • Are you sure that WPScripts_enqueue is being executed? Feb 13, 2020 at 19:33

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.