5 Best Ways to Clean Up and Optimize Your WordPress
After you’ve used WordPress for a while, you may want to consider optimizing and cleaning up your website, database and more. Using these techniques, you will free up disk space, optimize your database for best performance and hopefully, see a little increase in performance on your website.
Prevent Image Resizing Bloat
Have you ever logged in to your WordPress site via FTP and looked at /wp-content/uploads/? If you have, you may notice that every image you upload is resized multiple times automatically on every upload. These images are left there, permanently and will likely never be used.
It gets worse when you start adding plugins and customized themes because they also can add their own image sizes that WordPress will process on every upload. Thankfully, there’s a way to disable the default image sizes in your WordPress settings.
Go to Settings > Media.
Thumbnails may be used by your theme to display posts on your front end which you can check by right clicking the image in your browser and look for image viewing options. In Firefox, Right Click > View Image Info. In Chrome, right click image > open image in new tab. Either way, you will be able to see the image name and location which will tell you if the theme is using your original upload or a thumbnail.
If the thumbnail being used does not match what you show in Thumbnail size under media settings, then your theme is likely using its own image size. If that is the case, then you can set Thumbnail size, Medium size and Large size to 0 in all 6 fields.
Once saved, your WordPress will no longer create these additional images.
Clean Up Post Revisions
Every time you modify and save a post, WordPress defaults to saving a revision of your post. What this will do is create an entire copy of your post and save it to your database which can then be used to restore an old post in case you overwrite something important.
The problem is WordPress will store an umlimited amount of revisions on your posts which can take up a massive amount of space and bloat in your database. I’ve seen WordPress databases grow to the point of 6x the size it needs to be (we’re talking GBs of space here) with certain clients that have tons of posts and changes going on daily.
So what can be done to fix this issue?
Disable or Limit Post Revisions
You can disable post revisions on all content so that this doesn’t happen in the first place by adding a single line of code to your wp-config.php (the file that stores your database authentication settings). Add this line anywhere in your wp-config.php and revisions will no longer be saved:
define( 'WP_POST_REVISIONS', false );
Of course, you may decide that revisions are important, especially if you have a multi-author blog. If that is the case, then I’d recommend limiting post revisions to a maximum of 3 revisions to keep your database as bloat-free as possible while still having restore functionality. Here’s the code that you’d add to your wp-config-php:
define( 'WP_POST_REVISIONS', 3 );
Feel free to change the 3 to a number you are comfortable, however, my recommendation or lower number stands.
Database Revision Cleanup Plugin
Now that you’ve limited or eliminated post revisions, you still have an existing bloat in your database which can be severe depending on how long you’ve been adding / editing content on your website.
Let’s go ahead and clean out all the junk in the database.
Once installed and activated, go to Settings > WP Clean Up.
On that page, you will see the above screenshot with all of the options to clean up on your database. Obviously, I fudged the numbers in my screenshot because I keep my revisions disabled, however, you might be shocked at how much junk is stored in your database!
Be careful what you purge with this. For instance, we like to plan our content out in advance by saving draft posts. If we clicked delete under drafts, a full 2 days of research and post creation goes out the window. If you don’t do this, you may discover that using the Delete All button is fine.
Before deleting anything, I hope you followed that red warning at the top, back up your DB! Scroll down to the bottom of the WP Clean Up page and take note of how big your database is under Total.
Go ahead and clean up your database and let out a sigh of clutter relief.
Deactivate and Delete Unwanted Plugins
After discovering WordPress plugins, many users will go crazy installing and playing with all sorts of plugins to see how they work. The problem is, if you leave all these unnecessary plugins installed, it can delay the page loading speeds of your pages and slow down your overall site performance on both the front end and back end.
Go to Plugins in your WordPress dashboard and thoroughly evaluate your plugins and determine their value. Do you really need that Hello Dolly plugin? No. Delete it (sorry Matt).
While You Are At It, Delete Old Themes
Since you are in the deleting plugins mood, head over to Apperance > Themes.
You can delete a theme that you aren’t and will never use by clicking on the theme which will take you to a Theme Details overlay. On the lower right corner of that overlay, you will see a red Delete link that will allow you to delete the theme.
I recommend leaving Twenty Fifteen in your themes along with the theme you actively use. Just in case your theme breaks during an update or some other reason, WordPress can revert your site to the Twenty Fifteen theme if necessary.
Delete Spam Comments
If your site is even remotely popular, it is likely the comments section of your posts is being hit by spambots that add tons of spam comments into your database.
Go to Comments > Spam Tab
From here, you can scan your comments and look for legitimate comments received that were marked as spam. After restoring those, you can use the Empty Spam button to delete thousands of spam comments.
Depending on how much spam you’ve allowed to accumulate, this can be a major performance booster as it removes tens of thousands of comment entries in your database.
Shocked? If you want a way to manage your spam and virtually eliminate your spam problem, be sure to check out my fighting WordPress spam guide. Every client I manage takes advantage of the spam fighting techniques I use in that guide and not one has complained. 🙂
Since you are here, go to Comments > Trash tab and purge the comments there as well.
If your site is having a spam problem, I recommend purging your spam on a weekly basis to keep your database optimized.
Delete Those Unused Resized Images
In the occasional case where I’ve been hired to help cleanup a WordPress site that has been operational for over a year and they have expressed a desire to cut down on the disk space their site is using, I’ll use what I am about to mention to clean up the unused images and image references in the database.
For the most part, this isn’t necessary for most websites. If your site isn’t image heavy or hasn’t been online for too long, skip this and move on to the next cleanup tip below.
What this plugin does is scans your database and looks for images that aren’t assigned to posts on your website. What this plugin cannot do is prevent deletion of images that are being used naively by your theme.
Access the plugin by going to Settings > DNUI.
From here, go to the OPTION tab and check the option Show only image not used so that images used in your posts will be hidden from the results page. Also update the Quantity of image to search to 100. There’s no save button here, but after switching to the Scan Database tab, the settings are used.
Go ahead and select / delete unused images.
I hope this guide has helped you. If you see any value in the efforts to create this guide, please consider sharing it on social media, your email blast or link to it on your website. Thank you!