Last active
February 19, 2019 23:01
-
-
Save nydame/d189f3412cfb9404a307ac1d4a5c6687 to your computer and use it in GitHub Desktop.
WordPress filter that will add "async" to an enqueued script
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
#Assuming the script has already been enqueued with 'my-script' as a handle, add this to functions.php or to a plugin | |
add_filter( 'script_loader_tag', 'add_async_to_my_script', 10, 3 ); | |
function add_async_to_my_script( $tag, $handle, $src ) { | |
if ( $handle === 'my_script') { | |
$tag = '<script type="text/javascript" scr="' . esc_url($src) . '" async></script>'; | |
} | |
return $tag; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment