There are several ways to defer parsing of JavaScript in WordPress:
- 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.
- 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 );
- Use a content delivery network (CDN)
- 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 4 times, 1 visits today)
Was this article helpful?
YesNo
Last modified: March 3, 2023