How to remove unnecessary loading of styles and scripts in WordPress

An effective way to improve the performance of a WordPress site is to suppress the loading of unnecessary styles and scripts. The wp_deregister_style and wp_deregister_script functions are provided as a means to accomplish this.

wp_deregister_style('xxx'); 
wp_deregister_script('xxx');

However, the key to using these functions is to specify the “handle name” exactly. The handle name can be found in the id attribute of the <link> or<script> tag in the stylesheet or script. As an example, <link rel='stylesheet' id='main-style-css'... />, where main-style is the handle name.

You can refer to the official documentation for the handle names related to the default scripts of WordPress. On the other hand, if you want to check the handle name of the scripts added by the plugin, you can search for the function wp_enqueue_script in the plugin folder with a search tool (e.g. Grep) to identify the relevant handle name.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top