Skip to Content

Finding an Deregistering Assets Manually

How to find and manually deregister styles and scripts to optimize load time.

September 11, 2020

Additional Notes

Deregistering (and dequeuing) styles and scripts from WordPress is a way to optimize the load time of the website. Naturally, the fewer resources being loaded and processed means the load time will be faster.

Deregistering styles and scripts via Nebula Options

Nebula provides an advanced feature that scans the front-end for registered styles and scripts, and allows administrators to easily deregister them from the Nebula Options interface. This is a convenient solution, but there will always be edge-cases where manually deregistering and dequeuing assets is necessary.

It is recommended to try this method first– in the WordPress admin, navigate to Appearance > Nebula Options > Advanced where you will see the “Dequeues” panels (one for styles and another for scripts). You may need to “scan” the front-end for these to propagate– you can do this by clicking the button in this interface, or if you are using Sass, simply re-process Sass on the front-end. Then return to this options panel and you should see a list.

Note: Only non-core assets are available for deregistering in this method. If you are daring and want to deregister a core resource, you’ll need to do it manually.

Manually deregistering styles and scripts with Nebula

To help with this manual process, Nebula does provide a convenient function to deregister the asset, so all you need to do is find the name of the handle.

For reference, familiarize yourself with this Nebula function: nebula()->deregister()

WordPress conveniently adds an ID to link (for styles) and script tags which contains the handle we need. So load up the front-end and view the source code. Now look for the filename you want to remove and note the ID. Hypothetically, if we want to deregister a WP Bootstrap Gallery resource, the ID may be id="wp-bootstrap-gallery-css". The “-css” (or “-js” for JavaScript resources) is not part of the handle, so we can copy the rest of it to our clipboard: wp-bootstrap-gallery.

Now, in your functions file, hook into the wp_enqueue_scripts action and we can utilize Nebula’s deregister function. It’ll end up looking something like this:

add_action(‘wp_enqueue_scripts’, function(){ //Use this hook even for styles
nebula()->deregister(‘wp-bootstrap-gallery’, ‘style’);
}, 5000); //I like to use a super-low priority to make sure this happens last

If you still cannot find the name of the handle, you could try trudging through the plugin files themselves to find where it is registered. Nebula can help with this too– in the WordPress Dashboard, use the Developer Information metabox (which can be enabled via Nebula Options) search feature. Choose the plugin from the dropdown and then do a search for “wp_register_style(” or “wp_register_script(” and you’ll get a list of all registered styles/scripts respectively. If you don’t know which plugin is associated with the asset, you could select “All Plugins” from the dropdown and do the same search, but be prepared to do much more digging!

Note: This method only works when resources are properly registered with WordPress. If styles or scripts are simply (and improperly) hard-coded to output, it won’t be possible to deregister them this way. It is recommended to reach out to the developer to fix their implementation or find a new plugin.

Was this page helpful? Yes No

    A feedback message is required to submit this form.

    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!