Created
March 6, 2018 06:43
-
-
Save mahdi-alavi/1aceb2a1cc026b60ee0cb8ff0044a584 to your computer and use it in GitHub Desktop.
wordpres: Add async Attributes to Enqueue Scripts where Needed
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
/* 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