Created
August 9, 2021 03:09
-
-
Save totoprayogo1916/ba2995369b15068340acc9750f04d5dc to your computer and use it in GitHub Desktop.
defer script js - wordpress
This file contains 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
<?php | |
function defer_scripts( $tag, $handle, $src ) { | |
$defer = array( | |
'my-js' | |
); | |
if ( in_array( $handle, $defer ) ) { | |
return '<script defer src="' . $src . '" type="text/javascript"></script>'; | |
} | |
return $tag; | |
} | |
add_filter( 'script_loader_tag', 'defer_scripts', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment