Removes jQuery Migrate

Removes jQuery Migrate from the frontend to improve performance.

PHP
/**
 * Snippet Name:     Removes jQuery Migrate
 * Snippet Author:   coding-bunny.com
 * Description:      Removes jQuery Migrate from the frontend to improve performance.
 */

function cb_disable_jquery_migrate( $scripts ) {
    // Check if not in admin area and jQuery is registered
    if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
        $jquery_script = $scripts->registered['jquery'];
        
        // Remove jQuery Migrate dependency if present
        if ( ! empty( $jquery_script->deps ) ) {
            $jquery_script->deps = array_diff( $jquery_script->deps, [ 'jquery-migrate' ] );
        }
    }
}
add_action( 'wp_default_scripts', 'cb_disable_jquery_migrate', 150 );

How To Implement This Solution?

Leave a Reply

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

My Agile Privacy
This site uses technical and profiling cookies. You can accept, decline or customize cookies by pressing the desired buttons. By closing this policy you will continue without accepting.

Need help?

Choose one of the following options:

Powered by CodingBunny