SHARE
TWEET

Untitled

a guest Jun 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Add Async & Defer to certain scripts.
  3.  *
  4.  * @param string $tag      Script Tags to display.
  5.  * @param string $handle   Name of file specified above.
  6.  */
  7. function add_async_defer_attribute( $tag, $handle ) {
  8.  
  9.     $scripts = array( 'script-handle' );
  10.     foreach ( $scripts as $script ) {
  11.         if ( $script === $handle ) {
  12.             return str_replace( ' src', ' async="async" defer="defer" src', $tag );
  13.         }
  14.     }
  15.     return $tag;
  16.  
  17. }
  18. add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top