BBG Tips: Keep WordPress Tidy
WordPress is kind of magical. It gives site operators the power to quickly and effortlessly extend functionality, tweak design, and preview and post new content.
However, this power of immediate evolution – a key feature that has made so many insightful blogs about cats sleeping in weird places possible – can, over time, lead to clutter, increased hardware costs, and even security vulnerabilities.
Thankfully, a little bit of spring cleaning will go a long way. (Even if you don’t get around to it until the end of summer.) There are two areas to focus on:
First and foremost, conduct a quick census of the plugins installed on your site. If you notice any that aren’t actually being used, deactivate and delete them. All plugins contribute to the overall resource demands made of your server, so at best, unused plugins are needlessly slowing things down.
More importantly, plugins also add a lot of code to your site, code which may contain bugs or security weaknesses that a hacker would love to leverage against you.
Themes are another area that can grow quite cluttered over time. Even though inactive themes won’t contribute one way or another to your site’s performance, you should still delete them from the server as they might contain exploitable security vulnerabilities.
Byte for byte, orphaned thumbnails from uploaded images comprise the most wasted disk space on the average aging blog.
Every time an image is uploaded to WordPress, anywhere from a handful to a boatload of differently-sized thumbnails are generated and saved to the server. The precise dimensions of the thumbnails vary from theme to theme, so for sites that have switched designs, this can lead to a lot of images cropped at resolutions that will never be accessed again.
The plugin Force Regenerate Thumbnails will take care of this, deleting all existing thumbnails, and regenerating only those that are actually required by the current theme. Depending on how many images you have, this can take a while, so go make a sandwich if you’re hungry.
Your database, too, can easily start to look like the dark recesses of an attic, full of tangled and broken holiday decorations, old clothes, and haunted chests. The largest culprit here is usually post revisions.
WordPress maintains a history of all changes made to all posts.
This is nice because it allows you to review any changes you’ve ever made and rollback to a prior version at any time. But this also generates a lot of bloat, particularly if you can’t decide between
desert or dessert or desert or dessert.
Thankfully, this is something you can fix automatically by capping the number of revisions to some sane value. You can do this by adding the following to your wp-config.php file:
//specify the max # of revisions, 3 in this example define('WP_POST_REVISIONS', 3);
The WP_POST_REVISIONS setting is not enforced retroactively. To remove or prune excessive revisions for existing posts, you can use a plugin like Thin Out Revisions.
The trash can also be an area of database bloat. When you delete a post, it is moved to the trash. Just like the trash on your laptop or the trash in your kitchen, items will linger forever and ever until someone bothers to empty it.
You can automate this task in WordPress, at least, by adding the following to wp-config.php:
//specify the # of days before emptying, 5 in this example define('EMPTY_TRASH_DAYS', 5);
One last area of data bloat is one that can be really bad on some sites, and nonexistent on others: transient data. WordPress includes an API for temporarily storing arbitrary key/value pairs for later retrieval.
Most often, transient data is used to cache results that would otherwise take a while to generate, such as a response from another server (for example, a Twitter feed) or the end result of a really convoluted query (like: find all posts published on a Wednesday about apples or oranges but not mangoes…).
By default, WordPress stores these data in the wp_options table. Though each piece of information is given an expiration, WordPress does not do any automatic garbage collection.
Transient data is only removed if and when it is requested (after expiry).
If a given transient key is not reused, the data will outlive us all. Fortunately, you can keep expired transient data in check with the help of the aptly named plugin Delete Expired Transients.
That’s it! Happy cleaning!