Move jQuery and Migrate to footer?

I’ve seen this answer, but I’d like to move Migrate as well. I’m trying to move both jQuery and Migrate to the footer and change the jQuery to the CDN version. Here is the failed code I’ve tried (Why does this not move the scripts??):

// Move jQuery and jQuery migrate to the footer
function move_jquery_migrate( &$scripts ) {
    if(!is_admin()) {
        $scripts->remove( 'jquery');
        $scripts->remove( 'jquery-core');
        $scripts->remove( 'jquery-migrate');

        // From the WP script-loader.php with 'footer' added
        $footer = true;
        $suffix = SCRIPT_DEBUG ? '' : '.min';
        $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.12.3', $footer );
        $scripts->add( 'jquery-core', '//ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js', array(), '1.12.3', $footer );
        $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.4.0', $footer );
    }
}
add_filter( 'wp_default_scripts', 'move_jquery_migrate' );

However, the scripts still appear in the head, but the CDN URL has changed fortunately.

This answer works to move the built-in scripts to the footer:

// Move jQuery to the footer
wp_scripts()->add_data( 'jquery', 'group', 1 );
wp_scripts()->add_data( 'jquery-core', 'group', 1 );
wp_scripts()->add_data( 'jquery-migrate', 'group', 1 );

How can I achieve the move to the footer AND the CDN URL?

0

Leave a Comment