Skip to content

Instantly share code, notes, and snippets.

@premanshup
Created August 29, 2019 06:17
Show Gist options
  • Save premanshup/72199b22f58528f128124d51ec941326 to your computer and use it in GitHub Desktop.
Save premanshup/72199b22f58528f128124d51ec941326 to your computer and use it in GitHub Desktop.
Defer Parsing of Astra Theme JS
/**
* Add async attr to the Astra Script.
*
* @param string $tag Tag for the script.
* @param string $handle Handle for the script.
*
* @return string
*/
function add_async_attribute( $tag, $handle ) {
if ( 'astra-theme-js' === $handle ) {
return str_replace( ' src', ' async="async" src', $tag );
}
return $tag;
}
add_filter( 'script_loader_tag', 'add_async_attribute', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment