How to Remove Unused CSS and JavaScript from WordPress: A Comprehensive Guide.

CSS and JavaScript can take up a lot of unnecessary space in your WordPress site’s codebase, slowing it down in the process. In this article, we will show you how to find and remove unused CSS and JavaScript in WordPress.
unused css and javascript
95 / 100

Over time, your WordPress site can accumulate a lot of unnecessary CSS and JavaScript files. This can slow down your website’s loading time and cause other problems. In this article, we will show you how to easily remove unused CSS and JavaScript in WordPress. We will also provide some tips on how to keep your site’s CSS and JavaScript files under control.

There are a few different ways to remove unused CSS and JavaScript in WordPress. The first way is to use a plugin. A plugin is software that adds new features or functionality to WordPress. There are many plugins available that will help you remove unused CSS and JavaScript from your website.

The second way is to use a theme. A theme is a template for the design of a website. Many themes include built-in options for removing unused CSS and JavaScript.

The third way is to use a code editor. A code editor is a program that helps you write, edit, and debug code.

What is Unused CSS and JavaScript?

CSS and JavaScript are two of the most important front-end technologies on the web. They are used to style and add interactivity to web pages. However, not all of the code written in these languages is used on every page.

Unused CSS and JavaScript are files that are used on a website but are not needed. They can take up space and slow down the website. Files that are not used can be removed from the website to speed it up.

CSS files are style sheets that control the look and layout of a website. JavaScript is a programming language that is used to create interactivity on websites. Both of these files can be removed if they are not needed.

Unused CSS and JavaScript can be found by using a tool called Webpack. This tool scans your website for files that are not used and then removes them.

The unused code is called “bloat”, and it can slow down your website and make it harder to maintain. Fortunately, there are a few ways to reduce the amount of bloat in your CSS and JavaScript files. One is to use a minifier tool, which can remove unnecessary whitespace and comments from your code.

How to Find Unused Code on Your WordPress Site

Code is like a closet- it can quickly become cluttered and cramped if not organized. And, just like our closets, unused code on our websites can slow things down and cause problems. Here are tips for finding unused code on your WordPress site.

1. Speed Testing Tools

There are a number of speed testing tools that you can use to find unused code on your WordPress site. One such tool is called GTmetrix. It tests your website speed and provides a report that includes suggestions to improve your page speed. It also offers a waterfall chart that shows which elements are loading first and how long they are taking to load. Another tool is called PageSpeed Insights. It measures the performance of your website on both mobile and desktop devices and provides actionable recommendations to improve your page speed.

Unused CSS and JavaScript

Pingdom is also a popular tool that tests your website’s loading time from different locations around the world. It also provides a detailed report of what is slowing your website down.

2. Browser Developer Tools

One of the great things about being a web developer is the vast number of tools that are available to help us do our job. In this article, we will be looking at one such tool, the Browser Developer Tools, and how we can use it to find unused code on our WordPress site.

Browser Developer Tools is a built-in feature of most browsers that allows developers to view and edit the source code of web pages as they are loaded in the browser. It can be used to diagnose problems with web pages, find and fix errors, and examine and modify the CSS and JavaScript style.

Browser developer tools are a great way to find and clean up unused code on your WordPress site. This can help to speed up your site and improve performance.

The first thing you need to do is open the developer tools in your browser. In Chrome, this can be done by pressing Ctrl + Shift + I on Windows or Linux, or Command + Option + I on Mac.

Once the developer tools are open, select the “Sources” panel.

Browser Developer Tools

Removing Unused CSS and JavaScript With a WordPress Plugin

WordPress is a great platform for managing your website, but it can also be a bit of a resource hog. One way to clean up your WordPress site and make it run a bit more smoothly is to remove any unused CSS and JavaScript files. This can be done with the help of a WordPress plugin.

There are a number of different plugins that you can use for this purpose, but my personal favorite is Wp Rocket. It’s easy to use and it can help you clean up your site in just a few clicks.

There are a few options that make this relatively easy. For this example, we will use the Asset Cleanup plugin. You will find some more options below.

We are not going to use Wp Rocket since it’s a paid version and many might not be able to afford it.

1. Install the Plugin

The first thing you need to do is install the plugin. For that, go to Plugins > Add New and search for it by name. Locate Asset Cleanup in the search results and click the Install Now button, then click Activate once it’s done installing.

install asset cleanup plugin

2. Enable Test Mode

Before starting to remove unused CSS and Javascript code, you need to switch your WordPress site to test mode. That way, you are able to try out stuff without immediately affecting your website and potentially breaking things. All changes that you make are only visible to you as the administrator. Alternatively, use a development or staging site.

You find the option for test mode under Settings > Test Mode.

enable test mode in asset cleanup

Here, click the slider next to Enable Test Mode? and then Update All Settings at the bottom. When you have done everything right, there should be a green indicator next to Test Mode in the sidebar and it should say TEST MODE is ON in the WordPress admin bar.

asset cleanup test mode enabled

3. Start Unloading CSS and JavaScript

After that, you want to go to CSS/JS Manager.

asset cleanup css js manager

Here, on the first page, you see a list of CSS and JavaScript files that load on your homepage. To prevent them from doing so, simply use the slider where it says Unload on this page. Alternatively, use the checkbox Unload site-wide to disable a particular file for your entire website.

unload files in asset cleanup

Click Update at the bottom to save your changes.

At the top, you can use the tabs to do the same for posts, pages, custom post types, and media pages. Just search for a content piece by title or id and you get the same options as for the homepage.

remove unused css javascript from wordpress pages with asset cleanup

How to Manually Remove Unused CSS and JS in WordPress

WordPress is a great platform, but it can also be a bit bloated if you’re not careful. This is especially true if you’re not using all of the features that come with it. One way to clean up your WordPress site and improve performance is to delete any unused CSS and JS files. You can do this manually, but it can be a bit tedious.

There are a few good reasons to manually remove unused CSS and JS from WordPress:

-to speed up the loading of your pages

-to reduce the size of your pages, making them faster to download

-to improve the performance of your website

1. Delay JavaScript Files or Load Them Conditionally

One way to speed up the loading of your pages is to delay the loading of your JavaScript files. This can be done by adding the following code to your functions.php file:

function my_scripts_method() { if (!is_admin()) { wp_register_script(‘jquery’); wp_enqueue_script(‘jquery’); wp_register_script(‘my-script’, get_stylesheet_directory_uri() . ‘/js/my-script.js’); wp_enqueue_script(‘my-script’); } } add

JavaScript and CSS files are usually loaded indiscriminately on all pages of a WordPress website, whether they are used or not. This can slow down the loading of pages and even increase the size of the page.

It is possible to delay the loading of JavaScript and CSS files until they are needed. This can be done by adding the code to the functions.php file in the WordPress theme.

If a JavaScript or CSS file is not used on a particular page, it can be removed from the page by adding conditional comments to the code.


Removing unused CSS and JavaScript can help improve the performance of your WordPress website. In this article, we show you how to locate and remove unused files. If you have any questions, please leave a comment below. We’re happy to help!

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

side hustle

Online Side Hustles In Kenya That Pay Up To $50 Per Hour.

Kenyans are known for their entrepreneurial spirit, so it’s no surprise that there are many online side hustles you can consider. There’s no time like the present to start making some extra money. Whether you need to pay down debt, save for a rainy day, or just want to have a little more spending money, there are plenty of side hustles that can help you reach your financial goals.

affiliate programs

Should Freelancers Join Affiliate Programs?

As a freelancer, you may be wondering if you should join affiliate programs. The answer is: it depends. Affiliate programs can offer great benefits, but they may or may not be the best option for you.