Skip to main content
2 of 2
Beautifying code
Doug
  • 139
  • 1
  • 8

As per WP Code Snippet blog, it looks like this is one way:

Add this code snippet to your functions.php file.

// add async and defer to javascripts

function wcs_defer_javascripts ($url) 
{
    if (strpos($url, '.js') === FALSE) { 
        return $url;
    }
    if (strpos($url, 'jquery.js')) { 
        return $url;
    }
    return "$url' async onload='myinit()";
}
add_filter('clean_url', 'wcs_defer_javascripts', 11, 1);
Doug
  • 139
  • 1
  • 8