Skip to content

Instantly share code, notes, and snippets.

@mrkkr
Created April 16, 2018 08:48
Show Gist options
  • Save mrkkr/8515bc1f81491b827acf1475da3f39e9 to your computer and use it in GitHub Desktop.
Save mrkkr/8515bc1f81491b827acf1475da3f39e9 to your computer and use it in GitHub Desktop.
How to add async tag to script in Wordpress #php
///in functions.php
<?php
function add_async_attribute($tag, $handle) {
if ( 'SCRIPT_NAME' !== $handle )
return $tag;
return str_replace( ' src', ' async src', $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