Removing jQuery migrate and working with dependencies

by Brett   Last Updated July 22, 2018 19:08 PM

I have jQuery setup in my enqueue scripts section as a dependency, such as:

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts.min.js', array( 'jquery' ) );

Now, I want to remove jquery-migrate, but keep jQuery itself obviously, so I found this answer stating to do it like this:

add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );

function remove_jquery_migrate( &$scripts){
    if(!is_admin()){
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.2.1' );
    }
}

Firstly, I thought we had removed jQuery migrate here, so not sure what the need of adding the latest version of it is with the comment:

1.2.1 = latest version of jquery-migrate

Secondly, with the way I set my enqueue scripts up, how does that affect the dependencies since I have now removed jQuery and added jquery-core?

Is there a better way to handle this?



Related Questions



Create arrays from multiple functions

Updated May 27, 2016 08:03 AM



jQuery to show icon after .hide

Updated April 10, 2017 21:08 PM