Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add Async & Defer to certain scripts.
- *
- * @param string $tag Script Tags to display.
- * @param string $handle Name of file specified above.
- */
- function add_async_defer_attribute( $tag, $handle ) {
- $scripts = array( 'script-handle' );
- foreach ( $scripts as $script ) {
- if ( $script === $handle ) {
- return str_replace( ' src', ' async="async" defer="defer" src', $tag );
- }
- }
- return $tag;
- }
- add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement