Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove jQuery Migrate and add async to jQuery in WordPress
// remove jquery migrate
add_filter( 'wp_default_scripts', 'dequeue_jquery_migrate' );
function dequeue_jquery_migrate( &$scripts){
if(!is_admin()){
$scripts->remove( 'jquery');
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}
// add async to jquery
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if( is_admin() ) {
return $tag;
}
if ( strpos( $tag, "jquery.js" )) {
return str_replace( ' src', ' async src', $tag );
} else {
return $tag;
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.