Created
May 29, 2018 13:26
-
-
Save EastSideCode/c39a50e7948f57f366e3a709c357155d to your computer and use it in GitHub Desktop.
Remove jQuery Migrate and add async to jQuery in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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