Vital tips to clean and downsize your WordPress install

Delete post revisions

Since version 2.6, WordPress is automatically saving changes made to your posts, pages and drafts. This is indeed a very useful feature, however, it’s a good thing to delete unwanted revisions from time to time. You can do so using a dedicated plugin, or directly by editing your database throught PhpMyAdmin or via command line. (Click here for an explanation of how to do so if you don’t already know.)

The following SQL query will get rid of all post revisions, as well as of the associated metadata.

DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';

Additional tip: You can actually limit the amount of revisions per post that WordPress will save. To do so, edit your wp-config.php file and paste the following line in it:

define( 'WP_POST_REVISIONS', 3 );

Once saved, your WordPress install will only store the last 3 revisions. For more info about this constant, please refer to the Codex.

Get rid of unused plugins and themes

While it might seem obvious, the fact is that most WordPress bloggers tend to forget to delete plugins or themes they installed and don’t use anymore.

Deleting those will not only liberate free space on your server, it will most importantly prevent security loopholes due to an outdated plugin or theme. Unused plugins can be deleted directly through your WordPress dashboard (go to Plugins -> Installed Plugins and delete those you don’t need) while themes need to be deleted using your favorite FTP client (navigate to wp-content/themes and get rid of the unused ones.)

Clean up old meta information

Over time, as posts are updated, created, or deleted, the wp_postmeta table can become large and filled with unused data. Removing old meta data can be done with the Post Meta Manager plugin or with the following SQL query:

DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;

If you’d like more information about cleaning old metadata, you can check this post by InMotion Hosting.

Find and remove unused images

As blogs are using many images, if you’re looking on downsizing your WordPress install, image files are definitely something to look at when cleaning up your install.

The best way to find which images can be safely deleted is to use the Image Cleanup plugin which does a great job by finding unreferenced images (images which clutter your wp-upload folder while not referenced in posts or pages) and letting you delete them.

And while we’re talking about images, don’t forget to check out my image optimization guide in order to make your blog faster to load.

Trash those spam comments

If you’re not using an external comment system such as Disqus or De:comments, your blog probably attracts lots of spammers.

Thanks to Akismet, most spam comments are automatically caught and placed in a special “spam” queue. Don’t forget to empty that queue every now and then in order to keep things clean. To do so, simply log into your WordPress dashboard and navigate to Comments.

And if you haven’t emptied your spam queue for a year or so and find out that your blog database is actually storing 30,000 useless spam comments, no worries: here an SQL query that will get rid of all that junk in a blink of an eye:

DELETE FROM wp_comments WHERE wp_comments.comment_approved = 'spam';

Remove broken links

If your blog is older than 2 years, I would bet that it contains broken links. Broken links aren’t taking a lot of space on your database, obviously, but this isn’t a reason why you should carefully remove them.

Broken links are annoying for your visitors and bad for your SEO. So what to do? Just install the nifty Broken Link Checker plugin and let it find broken links.

Downsize your database by removing transients

Transients are a simple and standardized way of temporarily storing cached data in the database by giving it a custom name and a timeframe after which it will expire and be deleted. But sometimes, transients set by WP and countless plugins can take a lot of space in your database. Good news, transients can be safely removed with this simple query.

DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\_transient\_%');

Get rid of unused tags

Many blogs (including mine) stopped using tags years ago. But stopping to use tags doesn’t mean that there aren’t your old tags still present in your database.

So once again, the easiest way to delete them is by using a SQL query. Here is it:

DELETE FROM wp_terms wt
INNER JOIN wp_term_taxonomy wtt ON wt.term_id = wtt.term_id WHERE wtt.taxonomy = 'post_tag' AND wtt.count = 0;

Who needs trackbacks? Just delete them!

Trackbacks were more or less useful when I started blogging almost ten years ago. Nowadays, as ElegantThemes stated on their blog, spammers are pretty much the only persons to use them in 2016.

So, just get rid of them. Here’s a super simple SQL query to say goodbye to trackbacks.

DELETE FROM wp_comments WHERE comment_type="trackback";

Leave a Reply

Your email address will not be published. Required fields are marked *