Dequeue Unused CSS and JS in Envato WordPress Themes

by Fahim

A fresh ThemeForest corporate theme I installed last week dumped 48 stylesheets and 34 external JavaScript files onto a blank contact page. It dragged in Swiper, Owl Carousel, Isotope, Magnific Popup, FontAwesome 5, and WooCommerce cart fragments before painting a single word of text.

You don’t need to rebuild the entire theme from scratch to fix this. You just need to figure out which handles WordPress registered for those assets and rip them out on pages where they do nothing.

Terminal screen showing WordPress script handles and CSS asset sizes during performance debugging
Terminal screen showing WordPress script handles and CSS asset sizes during performance debugging

Map Enqueued Handles with Chrome DevTools and Network Inspection

Before you write a single line of dequeue code, you need handle names, not file URLs. The browser fetches files by path, but WordPress coordinates dependencies and print queues through handle strings registered via wp_enqueue_script and wp_enqueue_style.

Open your target page in Chrome, right-click, hit Inspect, and pull up the Coverage tab under More Tools. Hit reload with the record toggle turned on. You’ll get an immediate look at the exact percentage of unused bytes sitting in memory for every CSS and JS asset.

When I ran this on my test install, three slider libraries registered by the theme chewed through 312KB of JavaScript with 100% unused execution on standard blog posts. If you haven’t profiled your bundle before, run an audit on your Envato WordPress theme to pinpoint which bundled extras create the worst bottlenecks.

DevTools gives you filenames like owl.carousel.min.js, but it won’t show you whether the theme author named the internal handle owl-carousel, owl_carousel, or theme-owl. To grab the real handles straight from memory, you can dump the current asset queue in your local or staging environment.

Inspect Registered Handles with a Debug Filter

WordPress tracks all loaded assets in two global objects during page generation: $wp_scripts and $wp_styles. You can inspect everything waiting in the queue by hooking into wp_print_scripts on staging.

Drop this quick snippet into your child theme’s functions.php file while logged in as an administrator:

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

Load the page, view source, and search for CSS HANDLE:. You’ll get a clean, commented list of every handle registered by the theme and active plugins. Copy those strings into your scratchpad—these are the exact identifiers you need to pass into core dequeue functions.

Understand Asset Dependencies Before Stripping Files

Don’t just start stripping handles at random. WordPress builds dependency trees based on the arrays passed to wp_register_script. If handle B relies on handle A, pulling handle A while leaving B intact will throw nasty uncaught TypeErrors in the browser console.

Envato themes love bundling shared utilities like jQuery UI, imagesLoaded, or Waypoints. If you yank imagesloaded globally, you might take down your portfolio filters, image galleries, and mobile menu toggle all at once.

To see what a handle actually depends on before killing it, run this quick check in a staging environment:

add_action('wp_footer', function() { if (!current_user_can('manage_options')) { return; } global $wp_scripts; $target_handle = 'isotope'; if (isset($wp_scripts->registered[$target_handle])) { $deps = $wp_scripts->registered[$target_handle]->deps; error_log('Dependencies for ' . $target_handle . ': ' . print_r($deps, true)); }
});

Check your debug.log. If the handle doesn’t list critical dependencies tied to standard layout features, it’s safe to pull conditionally.

Dequeue Global Plugin Styles on Isolated Pages

ThemeForest staples like Contact Form 7 and WooCommerce load their stylesheets everywhere by default—including plain blog posts that don’t have a form or shopping cart anywhere in sight. Removing them from pages where they sit idle cuts down CSS parsing time immediately.

Head to your child theme’s functions.php and set up a dequeue function hooked into wp_enqueue_scripts. Make sure to use a late priority like 99 or 100 so your code executes after the plugins finish registering their assets.

function isitdev_dequeue_plugin_assets() { // Remove Contact Form 7 CSS and JS from everything except the contact page if (!is_page('contact')) { wp_dequeue_style('contact-form-7'); wp_dequeue_script('contact-form-7'); } // Remove WooCommerce generator tags, styles, and scripts on non-shop pages if (function_exists('is_woocommerce') && !is_woocommerce() && !is_cart() && !is_checkout()) { wp_dequeue_style('woocommerce-layout'); wp_dequeue_style('woocommerce-smallscreen'); wp_dequeue_style('woocommerce-general'); wp_dequeue_style('wc-blocks-vendors-style'); wp_dequeue_style('wc-blocks-style'); wp_dequeue_script('wc-add-to-cart'); wp_dequeue_script('woocommerce'); wp_dequeue_script('wc-cart-fragments'); }
}
add_action('wp_enqueue_scripts', 'isitdev_dequeue_plugin_assets', 99);

The official docs for wp_dequeue_style note that dequeuing pulls the stylesheet out of the current render queue without unregistering it completely. That means specific subpages or templates can still call it back when they actually need it.

Unload Heavy Envato Sliders and Carousels on Posts

Almost every multipurpose theme ships with Slider Revolution, LayerSlider, or a custom Slick wrapper. In 90% of site builds, those sliders only live on the homepage.

Here is how I target single posts and archives to dump unused slider scripts and styles completely:

function isitdev_dequeue_theme_sliders() { // Target single standard blog posts and archive listings if (is_single() || is_archive() || is_home()) { // Common slider stylesheets in Envato themes wp_dequeue_style('rs-plugin-settings'); wp_dequeue_style('owl-carousel'); wp_dequeue_style('owl-theme-default'); wp_dequeue_style('slick'); wp_dequeue_style('slick-theme'); // Common slider scripts wp_dequeue_script('rs-plugin-slider'); wp_dequeue_script('owl-carousel'); wp_dequeue_script('slick'); }
}
add_action('wp_enqueue_scripts', 'isitdev_dequeue_theme_sliders', 100);

Test your posts after saving. On my magazine test layout, stripping homepage slider junk from /blog/ and individual articles shaved 210ms off mobile Total Blocking Time.

If you imported this site via a one-click demo installer, you probably have database junk dragging down response times alongside asset bloat. Check our guide to clean up bloated wp_options autoload data to keep backend execution as lean as your new asset footprint.

Deregister vs Dequeue: Handling Stubborn Vendor Scripts

Sometimes you add a clean wp_dequeue_script(), clear your cache, reload, and the script still shows up in DevTools. Theme developers often force scripts into the head by hooking into priority 999 or printing them directly.

When a script refuses to leave the queue, pair wp_deregister_script with priority 9999. Dequeuing tells WordPress not to print the file on this request; deregistering scrubs the handle out of the global $wp_scripts catalog entirely.

function isitdev_force_deregister_stubborn_assets() { if (is_front_page()) { return; } // Deregister completely so dependent calls fail silently without outputting the tag wp_deregister_script('theme-portfolio-isotope'); wp_dequeue_script('theme-portfolio-isotope'); wp_deregister_style('magnific-popup'); wp_dequeue_style('magnific-popup');
}
add_action('wp_enqueue_scripts', 'isitdev_force_deregister_stubborn_assets', 9999);

Use this sparingly. If another script lists that deregistered handle as a hard dependency, WordPress will refuse to run the secondary script too because it can’t resolve the tree.

Prevent Broken Form Submissions and Broken Layouts

Stripping scripts will bite you if you don’t watch how your theme glues its UI together. Here are two real issues I ran into while tuning these filters.

1. WooCommerce Cart Fragments Break Cache Hit Rates

By default, wc-cart-fragments.js fires an admin-ajax POST request on every single page view to keep the header cart count synced. Killing it saves server load, but your header cart count will stay stuck at zero until the customer navigates to /cart.

If your header displays an active cart widget across the entire site, don’t dequeue wc-cart-fragments unless you swap in a custom localStorage script or kill the header counter on blog posts.

2. Google reCAPTCHA v3 Fails Silently

If you pair Contact Form 7 with Google reCAPTCHA v3, dequeuing contact-form-7 on pages without inline forms also kills the background reCAPTCHA script. If an unstyled modal or footer quote form pops up later, form submissions will fail silently with spam errors because the token generator never fired.

If you keep a lead form in your universal footer, leave the script alone or conditionally remove the footer form markup alongside the asset.

If your icon fonts vanish after dequeuing or reorganizing third-party CSS, check your headers. See our guide on how to fix CORS font loading errors on CDN to make sure your remaining icon fonts don’t get blocked by browser origin policies.

Production Snippet: Modular Dequeue Controller

Instead of littering twenty separate if checks all over functions.php, run them through an associative array controller. It keeps your rules readable and saves you from debugging spaghetti code when the theme updates.

<?php
/** * Selective Asset Dequeue Controller for Envato Themes * Add to child theme functions.php */
add_action('wp_enqueue_scripts', 'isitdev_selective_asset_cleanup', 999); function isitdev_selective_asset_cleanup() { // Never dequeue inside the WordPress customizer or site editor if (is_admin() || is_customize_preview()) { return; } // 1. Unload globally on pure text posts if (is_singular('post')) { $post_styles = [ 'owl-carousel', 'owl-theme-default', 'magnific-popup', 'elementor-post-slides', 'font-awesome-5' ]; $post_scripts = [ 'owl-carousel', 'isotope', 'magnific-popup', 'elementor-waypoints' ]; foreach ($post_styles as $style) { wp_dequeue_style($style); } foreach ($post_scripts as $script) { wp_dequeue_script($script); } } // 2. Unload checkout-related assets on marketing landing pages if (is_page_template('templates/landing-page.php')) { wp_dequeue_style('woocommerce-general'); wp_dequeue_style('woocommerce-layout'); wp_dequeue_script('wc-cart-fragments'); wp_dequeue_script('woocommerce'); }
}

Drop this in, update the handles to match your debug output, and click through your forms, mobile menus, and checkout flow in an incognito window.

Frequently Asked Questions

Can I put these dequeue hooks inside my parent theme functions.php?

No. The second you update your theme via the WordPress admin or Envato Market, your custom edits get wiped out. Always put these hooks inside a child theme’s functions.php or a custom mu-plugin.

Why does my page break when I dequeue FontAwesome?

Many Envato themes rely on FontAwesome for structural UI icons—like the mobile menu hamburger, dropdown carets, and search toggles. If you pull the stylesheet, those icons turn into missing glyph boxes. Always inspect your mobile menu in DevTools before stripping icon fonts.

Will dequeuing scripts fix Core Web Vitals issues?

It directly cuts down Total Blocking Time (TBT) and Interaction to Next Paint (INP). Removing 400KB of unused scripts frees up the main thread during initial page load, and dropping unused CSS clears render-blocking delays so hero elements paint faster.

Why did a script reappear after I dequeued it?

Theme authors sometimes hook scripts into wp_footer directly or inject them via wp_add_inline_script. If an asset is printed during the footer cycle, a standard-priority dequeue hook fires too early. Crank your hook priority to 9999 or check the theme’s footer templates for raw script tags.

Next Steps

Once you cut the excess script weight from your frontend, the difference in responsiveness is immediate. If you’re building sites regularly and want to cut out the manual dashboard setup altogether, check out our guide on how to install Envato themes and demo content using WP-CLI straight from the command line.

all_in_one_marketing_tool