Skip to content

Instantly share code, notes, and snippets.

@ravismakwana
Last active January 19, 2022 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravismakwana/0875ff473d7ab2fcf3ad5949de1564b6 to your computer and use it in GitHub Desktop.
Save ravismakwana/0875ff473d7ab2fcf3ad5949de1564b6 to your computer and use it in GitHub Desktop.
To add "Defer" into the script
<?php
if(!function_exists('defer_parsing_of_js')) {
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