Skip to content

Instantly share code, notes, and snippets.

@EastSideCode
Created May 29, 2018 13:26
Show Gist options
  • Save EastSideCode/c39a50e7948f57f366e3a709c357155d to your computer and use it in GitHub Desktop.
Save EastSideCode/c39a50e7948f57f366e3a709c357155d to your computer and use it in GitHub Desktop.
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