Dequeue Unused Scripts and Styles in Envato Themes

by Fahim

You buy a multipurpose theme from ThemeForest, import a clean starter demo, and pop open your browser DevTools. Your 400-word landing page just pulled in 42 stylesheets and 35 JavaScript files. That includes three carousel libraries, two lightboxes, and three icon font packs you never asked for.

You don’t need a heavy asset management plugin to fix this. You can track down every bloated stylesheet and script handle loading on your templates and selectively drop them with a few lines of clean PHP in your child theme.

Dequeue Unused Scripts and Styles in Envato Themes
Dequeue Unused Scripts and Styles in Envato Themes

Why Envato Themes Enqueue Assets on Every Page

Most commercial themes on Envato try to be twenty different themes in one zip file. The author bundles Owl Carousel, Swiper, Magnific Popup, Isotope filtering, and FontAwesome directly into the core build. To make sure user layouts don’t break out of the box, theme developers take the path of least resistance: they register and enqueue every single library globally on the wp_enqueue_scripts hook.

I audited a client’s corporate site running an Envato template last month, and their homepage was downloading 1.8MB of CSS and JS before rendering the hero section. Out of 77 network requests, about 60% were completely dormant files. If you picked up a template while following my guide to safely audit WordPress themes on Envato, this mess will look familiar.

WordPress tracks scripts using unique string identifiers called handles. If you know the exact handle registered by the theme or a bundled plugin, you can tell WordPress to drop that asset from the queue before it ever prints to the DOM.

Find the Enqueued Handles on Your Target Page

Before you can dequeue anything, you need the asset’s exact handle. Guessing names like owl-carousel or font-awesome rarely works because theme authors prefix handles with their own branding (something like theme-owlcarousel-style).

The fastest way to grab every active handle on a URL is dumping the global $wp_scripts and $wp_styles arrays into your page source while logged in as admin. You could check unused bytes using the Chrome DevTools Coverage tool, but the global arrays give you the exact string handles WordPress recognizes.

Drop this temporary helper snippet into your child theme’s functions.php:

add_action('wp_print_scripts', function() { if (!current_user_can('manage_options')) { return; } global $wp_scripts, $wp_styles; echo '' . PHP_EOL; foreach ($wp_scripts->queue as $handle) { echo '' . PHP_EOL; } echo '' . PHP_EOL; foreach ($wp_styles->queue as $handle) { echo '' . PHP_EOL; }
});

Save it, open your target page while logged in as an administrator, right-click, and hit “View Page Source”. Search the HTML for ENQUEUED SCRIPTS. You’ll see a clean list of handles printed as HTML comments:











Jot down the handles you want gone, then delete or comment out the diagnostic snippet so it doesn’t linger in production.

Hook Into wp_enqueue_scripts with High Priority

The most common mistake when dequeuing assets is firing your hook too early. WordPress runs hooks in order based on priority numbers (the default is 10). If a theme author enqueues Swiper at priority 20 and your child theme tries to dequeue it at priority 10, nothing happens. The asset hasn’t even been registered in the queue yet.

To reliably ditch assets, hook into wp_enqueue_scripts with a late priority of 100 or higher, then pass the handle to wp_dequeue_script() or wp_dequeue_style().

Here is what the basic dequeue block looks like in functions.php:

function isitdev_purge_theme_assets() { // Stylesheets to strip wp_dequeue_style('owl-carousel-css'); wp_deregister_style('owl-carousel-css'); wp_dequeue_style('magnific-popup-css'); wp_deregister_style('magnific-popup-css'); // Scripts to strip wp_dequeue_script('theme-owl-carousel'); wp_deregister_script('theme-owl-carousel'); wp_dequeue_script('magnific-popup'); wp_deregister_script('magnific-popup');
}
add_action('wp_enqueue_scripts', 'isitdev_purge_theme_assets', 100);

Running wp_deregister_script() right after wp_dequeue_script() ensures another plugin won’t re-enqueue that script later down the pipeline as an undeclared dependency.

Conditional Dequeuing: Target Specific Templates

You rarely want to strip libraries across the entire site. Your homepage probably doesn’t need Contact Form 7 or Magnific Popup, but your Contact and Portfolio pages obviously do. Nuking them globally will break interactive components.

Use WordPress conditional tags like is_front_page(), is_page(), is_single(), or custom post type checks inside your callback to remove assets only where they sit completely idle.

In this snippet, we strip slider scripts from single blog posts, and drop Contact Form 7 assets everywhere except our dedicated contact template:

function isitdev_selective_asset_cleanup() { // Strip Contact Form 7 everywhere except the contact page (slug: contact-us) if (!is_page('contact-us')) { wp_dequeue_script('contact-form-7'); wp_dequeue_style('contact-form-7'); } // Strip carousel and popup bundles from standard blog posts if (is_singular('post')) { wp_dequeue_style('owl-carousel-css'); wp_dequeue_script('theme-owl-carousel'); wp_dequeue_style('magnific-popup-css'); wp_dequeue_script('magnific-popup'); } // Strip heavy portfolio filtering scripts on the front page if (is_front_page()) { wp_dequeue_script('isotope-pkgd'); wp_deregister_script('isotope-pkgd'); }
}
add_action('wp_enqueue_scripts', 'isitdev_selective_asset_cleanup', 100);

Keep these rules organized. Grouping your logic by template condition makes audits much easier when you tweak page layouts months down the road.

Handling Broken Dependencies and Inline Script Gotchas

Here’s a bug I ran into on an Envato WooCommerce build: I dequeued a bulky masonry layout script from the blog index. As soon as I cleared the cache, the page crashed with Uncaught TypeError: $(...).isotope is not a function in the browser console.

Theme authors love printing initialization code into the footer with wp_add_inline_script() attached to their core theme bundle instead of the library’s handle. When you dequeue the library, the inline JS still fires, tries to invoke the missing library, and breaks execution for the rest of your scripts.

You have two ways to handle this without hacking the vendor’s parent theme:

  1. Check parent theme options: Decent themes have toggles to disable smooth scrolling, sticky sidebars, or animation triggers. Turn those off in the theme settings first so the inline scripts never get printed.
  2. Inspect theme main.js: If the primary theme script calls $('.slider').owlCarousel() without first checking if the jQuery plugin actually exists, you may need to dequeue the main script and re-queue a patched version in your child theme.

If you’re swapping an unoptimized library for a modern alternative or updating your asset paths, check my guide on how to fix theme missing style.css errors after an Envato update.

Verify Unused CSS Drops in Network Tab and Coverage

Once you push your dequeue functions to staging or production, open Chrome DevTools and switch to the Network tab. Filter by JS and do a hard reload (Ctrl+F5 or Cmd+Shift+R).

Check three things against your baseline:

  • Request Count: Look at the status bar at the bottom. If your requests went from 72 down to 44, your rules caught the files.
  • Transferred Size: Total payload should drop significantly. Stripping bundled FontAwesome 5 Solid and Brands alone routinely trims 300KB+ off the initial load.
  • DevTools Coverage: Hit Ctrl+Shift+P (or Cmd+Shift+P on Mac), type “Coverage”, and pick “Show Coverage”. Hit the record reload button. The red bars represent unused bytes. You should see far less dead CSS on first paint.

If your host uses persistent object caching, flush it after changing your asset hooks. This is especially important when you configure Redis Object Cache on your WordPress host.

Frequently Asked Questions

Why not just use an asset cleanup plugin?

Plugins like Asset CleanUp or Perfmatters work fine if you want a visual toggle interface. But putting a small snippet in your child theme adds zero database overhead, runs no extra background queries, and stays tracked in your Git history.

Will my dequeued changes get overwritten when the theme updates?

Not if you place your code in a child theme’s functions.php or inside a custom mu-plugin (must-use plugin). Never edit the parent theme files directly, because the author’s next release will wipe your edits.

What is the difference between wp_dequeue_script and wp_deregister_script?

wp_dequeue_script() tells WordPress not to print the script tag during the current request, but keeps the registration intact. wp_deregister_script() wipes the handle from memory entirely, so dependent scripts can’t quietly pull it back in.

Can I dequeue Gutenberg block library CSS on the front end?

Yes. If you’re building with custom HTML or a third-party builder, WordPress still enqueues wp-block-library and wp-block-library-theme by default. You can pass both handles to wp_dequeue_style() at priority 100.

Next Steps

After stripping dead stylesheets and scripts out of your templates, your server sends a much smaller DOM tree to the browser. The next bottleneck to fix is caching your surviving assets closer to your visitors. Take a look at our walkthrough on how to speed up WordPress with browser cache headers and StackPath CDN to get those lean files served without delay.

Official resources

all_in_one_marketing_tool