I can’t remove jquery-migrate (wordpress)

921 Views Asked by At

I’m trying to remove jquery-migrate.min.js. I tried these codes.

//Remove JQuery migrate

function remove_jquery_migrate( $scripts ) {
   if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
        $script = $scripts->registered['jquery'];
   if ( $script->deps ) { 
// Check whether the script has any dependencies

        $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
 }
 }
 }
add_action( 'wp_default_scripts', 'remove_jquery_migrate' );

or

*/
function isa_remove_jquery_migrate( &$scripts) {
    if(!is_admin()) {
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
    }
}
add_filter( 'wp_default_scripts', 'isa_remove_jquery_migrate' );

After I tried the plugins but I can’t remove jquery-migrate.min.js

It is still loading. screenshot: https://prnt.sc/s8qiel

How can I remove this? thanks

1

There are 1 best solutions below

0
revive On

Based on where WP registers jQuery Migrate (https://github.com/WordPress/WordPress/blob/267061c9595fedd321582d14c21ec9e7da2dcf62/wp-includes/script-loader.php#L749) and WP's wp_dequeue_script function.. we can do something like this.

    /**
     * Dequeue the jQuery Migrate script and hook it to the wp_print_scripts action, 
     * with a late priority (100), so that it fires after the script was enqueued.
    **/

    function wpdocs_dequeue_script() {
        wp_dequeue_script( 'jquery-migrate' );
    }
    add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );

Just keep in mind that folks that have deregistered jQuery Migrate have experienced lots of issues.. this is something that needs to be changed at the WP Core level IMHO