Defer Javascript in WordPress · GitHub

PHOTO EMBED

Thu Aug 05 2021 23:44:50 GMT+0000 (Coordinated Universal Time)

Saved by @rstringa

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);
content_copyCOPY

https://gist.github.com/alexander-young/af8f9305920cd0f5325646049c146552