Remove Plugin Stylesheets and Scripts - WordPress

Published on Dec 14, 2016 & tagged in WordPress, Page Optimization

Many WordPress plugins implicitly inject style sheets and JavaScript files into the page. If our theme is a customized one, we can eliminate some of these additional styles & scripts.

When you plan to optimize your WordPress site, you can find that these additional file request have some impact on our page load. So if possible, I suggest to optimize these additional file requests.

When scripts and styles are added properly, they use the wp_enqueue_style and wp_enqueue_script functions within the plugin files as such:

// Styles Format:  wp_enqueue_style($handle, $src, $deps, $ver, $media);
wp_register_style('pagination-style', plugins_url('style.css', __FILE__));

// Script Format:  wp_enqueue_script($handle, $src, $deps, $ver, $in_footer);
wp_register_script('jquery', '');

Those handle names are incredibly important because in our theme’s functions.php we have to add their counterpart calls of wp_dequeue_style and wp_dequeue_script functions:

// Remove from my page!

To remove plugin style sheets and scripts, we have to dig into the plugin code to find their script and style handles. But at the end, it will be worth.

Do you need any help on WordPress & Page Optimization?

I'm happy to help you. Just fill the form on contact page & I will get back to you within few hours.

Recent Posts

  1. Get current store details - Magento 1.9
  2. Simple ways to improve page conversion on product page
  3. Encrypt Email Addresses - PHP
  4. The add_image_size() function - WordPress best practices
  5. Remove page title using filter - WordPress