Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement