How To Fix Defer Parsing of Javascript Warning in WordPress Using Async

Category : Wordpress

You can do defer JS in WordPress and that is by editing your theme’s functions.php file.

Simply copy the code below and paste it at the bottom of your theme’s function.php file:

function defer_parsing_of_js ( $url ) {
  if ( FALSE === strpos( $url, '.js' ) ) return $url;
  if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' defer ";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );

Source of solution – https://www.collectiveray.com/defer-parsing-of-javascript-wordpress-async ( 4. Using functions.php tweaks )

Warning – After adding this code make sure that wordpress admin is working correctly. Trying editing page,posts etc.