Table of Contents
- 1 Before and After the performance test
- 2 How to remove unused CSS from Elementor website (manually)?
- 3 Benefits of Removing Unused CSS
- 4 Plugins will remove automatically from Website
- 5 #1 Get a baseline Performance score
- 6 #2 Open Chrome Developer tools & start capturing coverage Tab
- 7 #3 Identify Unused CSS problems from Coverage tab
- 8 #4 Test before you start removing it
- 9 #5 Install Asset clean plugin
- 10 Drawback of removing unused CSS (manually)
- 11 #6 Install CSS Used Chrome Extension
- 12 #7 Extract Used CSS using Used CSS Chrome Extension
- 13 #8 Include Dynamic style, CSS Classes and IDs to the extracted CSS
- 14 #9 Copy the minified/unminified code to your Code editor and save it
- 15 #10 Login to your control panel and upload the file
- 15.1 Step#1- Login to your control panel
- 15.2 Step#2- Select your Server
- 15.3 Step#3- Head over to Web Application
- 15.4 Step#3- Open File Manger
- 15.5 Step#4- Scroll down and open wp-content folder
- 15.6 Step#5- Create a new folder or use existing folder
- 15.7 Step#6- Create .css file inside combine-assets ( change if needed) folder
- 15.8 Step#7- Open the file and paste CSS from your code editor
- 16 #11 Install Header and Footer Scripts plugins
- 17 #12 Head over to header & footer scripts plugins textbox area (meta-box) of your page and link your stylesheet
- 18 #13 Unload all the stylesheet using Asset clean up plugin except Global styles
- 19 Recommended Links –
People do not realize the amount of CSS is being loaded on their page or post. If you test your site in Google page speed Insights (PSI) or any tools you will see a large amount of CSS loaded by your themes, 3rd parties plugins or page builder or theme builder if you’re using.
Removing unused CSS in WordPress is a tedious process and it can end up breaking your site if it isn’t done right.
Before and After the performance test
Accordingly to Google PSI reports, this page can potentially save over 60 KB which is huge, Your’s site may differ.
This question always comes in Facebook groups.
How to remove unused CSS from Elementor website (manually)?
Before I discovered this method, I was using Remove unused CSS from web.dev.Identifying and extracting used CSS from a small style sheet are way easy to detect. But if your website is built with Elementor thing can be really complicated and not easy to remove unused CSS.
Am I right?
That is why I wrote this tutorial to help you solve those problems that are recommended by Google Page Speed Insights (PSI).
Before you start implementing on your site, you might be asking yourselves, what are the benefits of removing?
I want the same answer too so that is why I asked the question a while ago on WP Speed Matters Facebook Group and this is what I got.
Benefits of Removing Unused CSS
The second point on my process might be incorrect because removing unused CSS wouldn’t fix Rendering Blocking resources, it will surely remove some of the file size and requests though.
Answers are still there and If you want to learn and improve your site performance and I highly recommended Joining WP Speed Matters Facebook Community. You will be going to love it and just by browsing in the groups you will learn tons of advanced stuff.
Plugins will remove automatically from Website
Right now Swift Performance (free and Pro) has the option to remove unused CSS from the website because last time I activate the feature all my hover effects, pseudo-class are all broken. ( You need to test it thoroughly).
Gijo Varghese’s Flying-Press plugin has the option to remove unused CSS by default ( See the screenshot below).
RapidLoad Power-Up for Autoptimize
RapidLoad is a WordPress plugin that extends Autoptimize. It automatically optimizes your site to run as fast as possible by removing unnecessary CSS and compressing relevant files.RapidLoad
No development necessary – optimize everything with one simple step.
#1 Get a baseline Performance score
First of all, we need to get a performance score on this page, later on, we can compare both the picture.
Accordingly, to Google Page Speed Insights, I can save over 60 KB of CSS, but your size may differ from mine.
#2 Open Chrome Developer tools & start capturing coverage Tab
For example, if you combined or merge CSS in your performance plugins then it is not easy to identify which CSS is in used or not, there are 2 ways to solve this issue –
- Remove page or post from caching this is one of the most common one and safest way. Re-added again.
- By adding ?nocache or any string to end of your URL to bypass cache. (This might serve uncached version and old data)
Step# 1 – Right click to open Inspect Elements
One of the easiest ways to open Developer tools is by right-clicking on any place with your mouse and click Inspect to open Inspect Elements panel.
Step# 2 – Customize and Open DevsTools
Click the Customize and Open DevsTools three-dot icon on the top right corner next to the cog icon
Step# 3 – Click the Coverage tab
#3 Identify Unused CSS problems from Coverage tab
Click the reload button to start capturing coverage. Next to URL Filter on the right side, there is an option to choose from there choose filter coverage by type to CSS.
Now you can identified resources from usage Visualization with Red and green color.
The red color of the bar is unused bytes and the green color is used bytes
You will get all the information like shortcut ,tips everything https://developers.google.com/web/tools/chrome-devtools/coverage
#4 Test before you start removing it
We figure it out which style sheets are not in use from usage visualization panel but how should we so sure, whether the file we’re removing is not going to break our style
Now head over to network tab then right-click on the style sheet you want to remove, then click the Block request URL this will open request blocking tab which lets you blocked requests you don’t want to load and then refresh the page and see if it doesn’t break. You do this process over and over
#5 Install Asset clean plugin
You can do the same thing with other asset management plugins too.
Now go to the page/post, you’re removing and toggle the “Unload on this page button” to unload CSS from loading.
Results after unloading CSS with Asset clean up plugin ( picture show – Before and after removal)
We have saved more than 20 KB of transfer size just by unloading with the help of asset clean up plugin. If you’re using lots of 3rd parties plugins or addons that add styling to your page, then you will save lots of resources and gain site performance boosts.
Can we even strip down more unused CSS or dead code from the page?
Absolutely, in the next step, we are going to learn how to remove unused CSS in WordPress with the help of Chrome extension manually.
Drawback of removing unused CSS (manually)
- It is a time-consuming process.
- Removing unused CSS is not worth it if you constantly updating your pages.
- Great for the smaller website but not for a large website.
#6 Install CSS Used Chrome Extension
After we have saved more than 20 KB of transfer size just by unloading CSS with Asset clean up plugin, we still have tons of unused CSS problem that can be removed but not possible.
With the help of the Chrome extension I used, we will be able to remove unused CSS completely.
#7 Extract Used CSS using Used CSS Chrome Extension
After we have installed the Chrome extension. Now open Chrome Developer tools then from there head over to Elements panel and you will see the DOM tree from there select <html
#8 Include Dynamic style, CSS Classes and IDs to the extracted CSS
To Detect dynamically injected CSS classes by Used CSS chrome extension, we need to first interact the page, in this case, it will be hamburger menu and then repeat number 7 process.
#9 Copy the minified/unminified code to your Code editor and save it
Now copy the minified/un-minified code to your code editor ( Visual Studio Code) and save it as .css file format. So you can upload it or copy the code.
#10 Login to your control panel and upload the file
In this step, we are going to upload a file through the control panel or cPanel or FTP manage. I am currently using Runcloud as my control panel (cPanel) and Vultr (High Frequency) as my storage so the process is simple.
Step#1- Login to your control panel
Step#2- Select your Server
Step#3- Head over to Web Application
Now head over to Web Application area and choose your root.
Step#3- Open File Manger
Step#4- Scroll down and open wp-content folder
After you open File manager, you need to scroll down to the end and find the wp-content folder. This folder contains everything like your media, Plugins, Themes, cache etc
Step#5- Create a new folder or use existing folder
After we open the wp-content folder there will be an existing folder, if you’re using any Performance plugins like swift or wp-rocket then there is a chance it will create a folder automatically for you called cache.
Step#6- Create .css file inside combine-assets ( change if needed) folder
After you have created folder ( combine-assets), you need to create a .css file that stores our extracted CSS from number #8
Give a file name (Laura-brehm) and save it as .css format
Step#7- Open the file and paste CSS from your code editor
Open the file and copy all the CSS ( Ctrl + A and Ctrl + C) from your code editor and paste it inside the File editor (laura-brehm.css file) and save it.
Or you can install File manager plugin from Wp Repository to upload your file, later on, you can remove the plugin. If you want the guide please let me know I will add it here.
This plugin is very useful, it allows you to add scripts or style on head tag without touching your theme php. You can add it as globally or page or post basis.
You need to go the page or post you’re editing then above Asset clean up plugin meta box there is a textbox added by Header and Footer Scripts plugins. Inside that, you need to link your style sheet or simply inline all the CSS.
<link rel="stylesheet" id="name-your-css" href="https://yourdomain.com/wp-content/cache/combine-assets/laura-brehm.css" >
#13 Unload all the stylesheet using Asset clean up plugin except Global styles
Now we have linked the extracted used style sheet using header & footer scripts or Code Snippet plugins. Now you can safely unload all the CSS using Asset clean up without even breaking or exclude global stylesheets.
If you don’t want to go through all this process you can get Flying-press plugin because plugins I recommended above and here will remove your Unused CSS automatically which make super easy and faster.
- WP Speed Matters ( Focus more on Performance than anything)
- WP Johnny – The Ultimate WordPress Speed Optimization Guide
- web.dev – Fast Load Times
Advice: If you removed unused CSS from post and page completely, you will not gain a major boost on your Performance score. Here the post web.dev lighthouse report that has unused CSS problems if you are interested to see.