jQuery Migrate is a JS library that ensures older jQuery code remains compatible with newer versions. But if you want to Disable jQuery Migrate in WordPress then I will show you how to disable jQuery Migrate in WordPress. I will give you a simple code that easily removes jQuery Migrate from WordPress without any plugins.
WordPress started shipping with jQuery Migrate in version 3.6. This was done to help ensure that older themes and plugins would continue to work on newer versions of WordPress. However, as jQuery has evolved, jQuery Migrate has become less necessary. In fact, it can actually slow down your WordPress website.
Table of Contents
What is jQuery Migrate
jQuery Migrate is a vital tool for website developers. It acts as a bridge between old and new jQuery versions, ensuring smooth functionality and compatibility. This tool identifies outdated elements in older jQuery code and restores them to work seamlessly with newer jQuery versions. By preserving these connections, jQuery Migrate helps websites remain functional and user-friendly even as technology advances.
In short, jQuery Migrate helps to preserve the compatibility of older jQuery code with newer versions of jQuery.
In WordPress, jQuery Migrate is important for two reasons:
- Compatibility: WordPress has been using jQuery since version 2.8. However, jQuery has been through many updates since then, and some of the older code in WordPress themes and plugins may not be compatible with the latest version of jQuery. jQuery Migrate helps to bridge the compatibility gap between old and new jQuery code so that your WordPress website will continue to work even if you update jQuery.
- Performance: jQuery Migrate can also improve the performance of your WordPress website. This is because it allows you to use older, more lightweight versions of jQuery code. The newer versions of jQuery are more powerful, but they can also be more resource-intensive. If your WordPress website is not using the latest version of jQuery, then using jQuery Migrate can help to improve its performance.
Overall, jQuery Migrate helps to ensure compatibility and performance, and it can be a valuable tool for developers who need to maintain older code.
Why do we Disable jQuery Migrate?
jQuery Migrate can also slow down your WordPress website. This is because it adds additional code that is not necessary for most websites. Studies have shown that disabling jQuery Migrate can improve the performance of your WordPress website by up to 30%.
jQuery Migrate is no longer necessary for most websites these days. Most modern themes and plugins are compatible with newer versions of jQuery without the need for jQuery Migrate. Also, most Themes like Kadence(that I use), and GeneratePress do not depend on jQuery, so they do not load jQuery on frontend side.
Note: WordPress 5.5 and higher no longer ship with jQuery Migrate enabled by default, unless you are using a theme or plugin that requires jQuery Migrate.
How to Disable jQuery Migrate in WordPress (Without Plugin)
Here is a step-by-step guide to disable jQuery Migrate in WordPress:
Step 1: Take a Backup –
In this method, we are using a customer code that can break your website. So make sure you take a full backup of your website. Use UpdraftPlus backup plugin that I use and recommend to everyone. It is free.
Step 2: Edit Theme’s functions.php file –
Access your theme’s functions.php
file via the WordPress dashboard under “Appearance” > “Theme Editor.” Please choose the right theme that is activated on your site from drop-down. Here you need to add a simple code that is provided in Step 3.
Step 3: Add the Disabling Code –
Add the below code at the end of your funcation.php and save it. Please add this code to the activated theme otherwise this won’t work. Also, please always add this code after updating the theme.
//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' );
How to Disable jQuery Migrate with Plugin
The above method is not convenient for most users. Also, you always need to manually add jQuery removal code to your theme every time when your update your theme if you are not using any child theme.
So here is another method to remove jQuery migrate in WordPress with a simple lightweight 14KB plugin –
- Go to your WordPress dashboard and click on Plugins.
- Click on the Add New button.
- Search for the Remove jQuery Migrate plugin.
- Click on the Install Now button.
- Click on the Activate button.
Once you activated, clear the cache. This plugin will disable jQuery migrate from your WordPress website. To enable jQuery Migrate again on your WordPress website, simply deactivate this plugin.
Conclusion
Disabling jQuery Migrate can improve the performance of your WordPress website. It can also help to prevent compatibility issues with newer versions of jQuery. Many plugins that we use on our WordPress even do not use old jQuery.
So if your site is still using jQuery migrate and your want to disable jQuery then you can easily do it by either adding code in function.php or by installing a plugin. After removing jQuery, you will see better speed scores in PageSpeed Insight tool.
If you find any issues or have any suggestions, please share them in the below comment section.
Thanks for sharing correct information on this topic Disable jQuery Migrate in WordPress.
You’re welcome