Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mahdi-alavi/1aceb2a1cc026b60ee0cb8ff0044a584 to your computer and use it in GitHub Desktop.
Save mahdi-alavi/1aceb2a1cc026b60ee0cb8ff0044a584 to your computer and use it in GitHub Desktop.
wordpres: Add async Attributes to Enqueue Scripts where Needed
/* Add async Attributes to Enqueue Scripts where Needed.
=========================================================================== */
function itl_script_tag_defer( $tag, $handle ) {
if ( is_admin() ) {
return $tag;
}
if ( strpos($tag, '/wp-includes/js/jquery/jquery') ) {
return $tag;
}
return str_replace( ' src', ' async src', $tag );
}
add_filter( 'script_loader_tag', 'itl_script_tag_defer', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment