WordPress Snippets at WPcustoms

Load jquery migrate only in admin panel

If you check your site with google’s pagespeed you might want to see a message to reduce your header js and css files which blocks site rendering.
I first dropped jquery.migrate which is automatically added by WordPress completely but then found a few things not working anymore in my admin area (i.e. adding tags). So why not include jquery migrate only in your wp-admin panel? The second function does exactly this. Handle with care and check your site carefully if it works without errors on your frontend. It works fine so far on my end. Let me know by commenting this post if you experience any problems.


/**
 * Snippet Name: Load jquery migrate only in admin panel
 * Snippet URL: http://www.wpcustoms.net/snippets/load-jquery-migrate-admin-panel/
 */
 // remove jquery migrate on frontend
function wpc_dequeue_jquery_migrate( &$scripts){
    $scripts->remove( 'jquery');
    $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
add_filter( 'wp_default_scripts', 'wpc_dequeue_jquery_migrate' );


// fix for broken admin stuff - we enqueue jquery migrate only in wp-admin
function wpc_jquery_migrate_admin_enqueue() {
        wp_enqueue_script('jquery-migrate');
}
add_action('admin_enqueue_scripts', 'wpc_jquery_migrate_admin_enqueue');