Last active
March 12, 2018 10:44
-
-
Save walterebert/787d312c6cd8b6ffef03 to your computer and use it in GitHub Desktop.
WordPress snippet: Load JavaScript asynchronously
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 my_async_scripts( $tag, $handle, $src ) { | |
| switch ( $handle ) { | |
| case 'picturefill': | |
| case 'wp-embed': | |
| $tag = str_replace( ' src=', ' async defer src=', $tag ); | |
| break; | |
| } | |
| return $tag; | |
| } | |
| add_filter( 'script_loader_tag', 'my_async_scripts', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment