Remove jQuery Migrate on the front end
Stop WordPress loading jQuery Migrate on the front end of your site. jQuery itself still loads, and the admin area is unchanged.
// Load jQuery without jQuery Migrate on the front end. The admin area keeps it.
add_action(
'wp_default_scripts',
function ( $scripts ) {
if ( is_admin() || empty( $scripts->registered['jquery'] ) ) {
return;
}
$scripts->registered['jquery']->deps = array_diff(
$scripts->registered['jquery']->deps,
array( 'jquery-migrate' )
);
}
);
What it does
When a theme or plugin loads jQuery, WordPress also loads jQuery Migrate. It helps very old jQuery code keep working, but up-to-date themes and plugins don't need it.
This snippet removes jQuery Migrate from jQuery's dependencies on the front end only. The admin area keeps it, because some admin screens still rely on it.
Good to know
- Check your sliders, forms, menus and pop-ups after adding it. If something stops working, turn the snippet off.
- Clear your page cache so visitors get the updated pages.