Last active
March 11, 2018 17:07
-
-
Save NickDuncanZA/a0effc600b8c7c0a908388688a68e4f9 to your computer and use it in GitHub Desktop.
Defer certain WordPress scripts
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
/** | |
* Add 'defer' to certain scripts, dependant on their handle | |
*/ | |
function fdFS2d_theme_make_script_defer( $tag, $handle, $src ) { | |
$script_handles = array( | |
'wplc-server-script', | |
'wplc-user-script', | |
'wplc-md5', | |
'wplc-node-server-script', | |
'wplc-user-js-emoji-concat', | |
'wplc-user-events-script', | |
'wplc-theme-modern', | |
'wplc-user-pro-editor', | |
'wplc-user-pro-events-script', | |
'wplc-user-pro-features', | |
'wplc-user-jquery-cookie', | |
'bleeper-action-script', | |
); | |
if ( in_array( $handle, $script_handles ) ) { | |
return str_replace( '<script', '<script defer', $tag ); | |
} | |
// Just return the default tag if we didnt get a match above | |
return $tag; | |
} | |
add_filter( 'script_loader_tag', 'fdFS2d_theme_make_script_defer', 10, 3 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment