Last active
June 8, 2020 19:52
-
-
Save jbd91/5a8aee079c43df8756772dd03fcffcdb to your computer and use it in GitHub Desktop.
async
This file contains hidden or 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
function add_async_forscript($url) | |
{ | |
if (strpos($url, '#asyncload')===false) | |
return $url; | |
else if (is_admin()) | |
return str_replace('#asyncload', '', $url); | |
else | |
return str_replace('#asyncload', '', $url)."' async='async"; | |
} | |
add_filter('clean_url', 'add_async_forscript', 11, 1); | |
// BEST METHOD | |
// Make JavaScript Asynchronous in Wordpress | |
add_filter( 'script_loader_tag', function ( $tag, $handle ) { | |
if( is_admin() ) { | |
return $tag; | |
} | |
return str_replace( ' src', ' async src', $tag ); | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment