Skip to content

Instantly share code, notes, and snippets.

@roborourke
Created April 23, 2014 10:44
Show Gist options
  • Save roborourke/11210430 to your computer and use it in GitHub Desktop.
Save roborourke/11210430 to your computer and use it in GitHub Desktop.
<?php
// use the script loader filter to target specific scripts by handle
add_filter( 'script_loader_src', function( $src, $handle ) {
if ( in_array( $handle, array( 'script-handle' ) )
add_filter( 'clean_url', 'mod_script_tag', 11, 1 );
return $src;
}, 10, 2 );
// change the return value to add any attributes you need on the script tag
if ( ! function_exists( 'mod_script_tag' ) ) {
function mod_script_tag( $src ) {
remove_filter( 'clean_url', 'mod_script_tag', 11 );
return "{$src}' async charset='utf-8";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment