WordPress loads jQuery.migrate automatically:

How can I disable it without plugins? I didn’t find code in functions.php with enqueue.

It loads from /wp-includes. How can I disable it?

2 s
2

jQuery Migrate is nothing but a dependency of the jQuery script in WordPress, so one can simply remove that dependency.

The code for that is pretty straightforward:

function dequeue_jquery_migrate( $scripts ) {
    if ( ! is_admin() && ! empty( $scripts->registered['jquery'] ) ) {
        $scripts->registered['jquery']->deps = array_diff(
            $scripts->registered['jquery']->deps,
            [ 'jquery-migrate' ]
        );
    }
}
add_action( 'wp_default_scripts', 'dequeue_jquery_migrate' );

This will prevent the jQuery Migrate script from being loaded on the front end while keeping the jQuery script itself intact. It’s still being loaded in the admin to not break anything there.

In case you don’t want to put this in your own plugin or theme, you can use a plugin like jQuery Light that does this for you.

Tags:

Leave a Reply

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