Created
January 15, 2020 02:32
-
-
Save alexander-young/af8f9305920cd0f5325646049c146552 to your computer and use it in GitHub Desktop.
Defer Javascript in 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
function defer_parsing_of_js($url) | |
{ | |
if (is_admin()) 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