There are several ways to defer parsing of JavaScript in WordPress:

  1. Using a plugin: There are several plugins available that can help defer parsing of JavaScript in WordPress, such as Async JavaScript, WP Defer JavaScript, and WP Optimize.
  2. Manual method: You can also manually defer parsing of JavaScript by editing your theme’s functions.php file. You can add the following code to the file:
Copy codefunction 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 );
  1. Use a content delivery network (CDN)
  2. Minify and concatenate your JavaScript files.

It is important to note that some plugins and themes may not work properly with deferred JavaScript, so it is always a good idea to test your website after making these changes.

(Visited 13 times, 1 visits today)
Was this article helpful?
YesNo
Close Search Window