-
-
Save jevgen/4b39269c002ccc2c5c44311a8a28a196 to your computer and use it in GitHub Desktop.
Defer enqueued JS scripts in Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'script_loader_tag', 'yankiara_defer_scripts', 10, 3 ); | |
function yankiara_defer_scripts( $tag, $handle, $src ) { | |
$defer = array( 'script-handle-1', 'script-handle-2', 'script-handle-3' ); | |
if ( in_array( $handle, $defer ) ) | |
return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "\n"; | |
return $tag; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment