Last active
January 3, 2020 20:02
-
-
Save vanaf1979/67abaa17998dbddd6f0830d3f7048ffb to your computer and use it in GitHub Desktop.
Add a action to enqueue stylesGist for my "WorpdPress: Css Styles and Javascripts in theme development (In depth)" article: https://since1979.dev/wordpress-css-styles-and-javascripts-in-theme-development-in-depth/
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 my_theme_optimize_script_tags( $tag , $handle , $src ) | |
{ | |
/* add async defer attributes */ | |
$defer = ( $handle == 'my-theme-scripts' ) ? 'async defer' : ''; | |
return "<script id='{$handle}' {$defer} src='{$src}'></script>" . "\n"; | |
} | |
add_filter('script_loader_tag', 'my_theme_optimize_script_tags', 10, 3); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment