Created
December 16, 2019 13:31
-
-
Save ledovej/e06cc01f1ad64a0b6792f5fcfc2f9554 to your computer and use it in GitHub Desktop.
Defer javascript
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
function defer_parsing_of_js( $url ) { | |
if ( is_user_logged_in() ) return $url; //don't break WP Admin | |
if ( FALSE === strpos( $url, '.js' ) ) return $url; | |
if ( strpos( $url, 'jquery.js' ) ) return $url; | |
return str_replace( ' src', ' defer src', $url ); | |
} | |
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment