How to selectively dequeue a script on individual post

Lot of plugins. Not sure what to do??

All of a sudden you may realise that you already have quite a lot of plugins on your website and probably some of those plugins are slowing your site down. That’s the point of time you may decide to review your plugins but at that point it is very difficult to imagine the impact of deactivating a certain plugin.

Here is a simple trick we can use to review our plugins and make sure atleast our important pages do not break.

Idea

The idea is to try and dequeue or remove a script on a page by page basis or post by post basic. Using this approach we are not deactivating the plugin on the entire site but we are just deactivating or removing it on just a single post or page. This way we can study the impact of removing the plugin on our most important pages/posts just so that we are sure it won’t break our site and we feel more comfortable to deactivate the plugin entirely on our site.

So how do we achieve this

Step 1: Print all the script handles used on a page/post

Step 2: Create a custom field

Create a custom field named wpi_selective_scripts_dequeue on our post/page and add bar separated (|) handles of the scripts which you wish to remove from the page (referring to list generated in step 1)

Step 3: Dequeue the script for that page/post