Created
June 13, 2019 16:30
-
-
Save addzycullen/332b2831c72685b365b07811d3a2cdba to your computer and use it in GitHub Desktop.
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
/** | |
* Add Async & Defer to certain scripts. | |
* | |
* @param string $tag Script Tags to display. | |
* @param string $handle Name of file specified above. | |
*/ | |
function add_async_defer_attribute( $tag, $handle ) { | |
$scripts = array( 'script-handle' ); | |
foreach ( $scripts as $script ) { | |
if ( $script === $handle ) { | |
return str_replace( ' src', ' async="async" defer="defer" src', $tag ); | |
} | |
} | |
return $tag; | |
} | |
add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment