🌓

Ultimate WordPress Performance Tip List to speed up and save up to 80% of space 22 easy, intermediate and advanced tips and tricks to make your Wordpress website run extremely fast and use less disk space to gain noticeable improvements

by
on September 13, 2011
(7 minute read)

This is a list of actions and tips to take in order to make your WordPress website faster and improve its performance. You should follow these steps at least once every 3-6 months depending on your website’s activity in order to keep it clean and to increase its performance to a top level. If you have been using WordPress for a while and have never cleaned it you may be surprised at how much database space you can save up, the last cleaning I did to a client saved 82% of space going from 132MB to 23MB.

Please donate to keep this server up

Before running any queries in the database take backups of everything and make sure no one is editing any post or page while cleaning WordPress.

The database

1. Delete post revisions

Create a backup of the revisions first by selecting and exporting them:

SELECT * FROM wp_posts WHERE post_type = 'revision'

Then delete them and be amazed at the big space savings:

DELETE FROM wp_posts WHERE post_type = 'revision'

2. Limit post revision

By default, WordPress saves every revision of a post. This can make your wp_posts table 2 to 10 times bigger than necessary. In your wp-config.php file, add this:

define('WP_POST_REVISIONS', no_of_revisions);

Leaving number of revisions to 10 is more than enough, if your blog is used by 1 or 2 people then 5 may be even better.

3. Disabling post revision

You can disable post revision completely (although I would personally leave it just in case). To do that:

define('WP_POST_REVISIONS', false);

4. Deleting spam comments

If you don’t use Akismet or any other effective spam control service, spam messages can bloat your database waiting to be approved or deleted. You can either go to the WordPress Administration Panel > Comments and delete them or just head to MySQL and execute this:

DELETE FROM `wp_comments` WHERE `comment_approved` NOT LIKE '1'

This query will delete both spam, pending and trashed comments.

5. Disable comments in all your WordPress blog posts

Some WordPress sites get loads of real comments every day but some don’t. If your website just receives spammy comments and you guess one in a million will be real, I may suggest you to consider disabling them, not only will this save you time and loads of database space but will also increase the performance and loading speed of your pages. You can install Disqus which allows people to post comments through several ways (Twitter, Facebook, manually, etc.) and has very effective spam protection. If you don’t get many comments and performance/SEO is a must then add a link to a Contact Us page next to the post and encourage people to contact you that way.
To disable comments go to Settings > Discussion and disable these two checkboxes:

  • Allow link notifications from other blogs (pingbacks and trackbacks.)
  • Allow people to post comments on new articles

This will disable comments only in the new posts you create from now on. To disable comments (and pings) in your existing blog posts execute this query in your MySQL:

UPDATE `wp_posts` SET `comment_status` = 'closed', `ping_status` = 'closed';

6. Delete plugin log tables

Some plugins store log files in your database but these can sometimes get way too big if the plugin developer hasn’t set a limit. Check your database tables and look for big tables or tables containing log in their name.

7. Delete old plugin tables

Some WordPress plugins create tables in your database and when you delete them, the tables are still there to keep your configuration if you ever install the plugin again. If you do not intend to install them anymore, have a quick look at your database tables and see if you find any remains of those plugins.

8. Delete old plugin option parameters

Some WordPress plugins also store information in the wp_options table.

9. Optimize, analyze, check and repair your tables

After deleting so many records, it is good to optimize your tables again to remove any over-heading data.

10. Check your WordPress table’s Primary and Index Keys

advanced tips to optimize wordpress database

It’s not just about size what makes a database run slower but the way it is indexed. Once you have cleaned your database, it is time to check that MySQL is indexing everything properly. phpMyAdmin is a very powerful tool and may also warn you about it or suggest better ways. I suggest you read more about MySQL and how it works to understand how queries are made, how to index properly and how a database works on the background.

11. Delete orphaned post meta

Delete any post meta that may have been left behind during cleaning or by old plugins. Replace “wp_” with your prefix.

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

Thanks to Patrick for this one

The server

11. Remove old plugins completely

Connect with your FTP and remove any old plugins you are not using anymore. Don’t bother to remove Hello Dolly as it will get installed again in the next update.

12. Search for the upgrade folder

Sometimes (usually on failed WordPress automatic upgrades) an upgrade folder is created which contains some temporary files that you can remove.

13. Search for old backups

Delete old backups from the web server and store them locally, also search inside your plugins in case any of them stores backups there.

14. Search for cache files

If you use TimThumb or any other file caching system it is a good idea to, once in a while, clean the complete cache folder to remove items not used in a long time.

WordPress settings

You’ve now cleaned the database and the server files and probably made the server much quicker. You can now tweak your WordPress installation to make it work even faster.

15. Upgrade to the latest version

Seems quite obvious but it really makes a difference and protects you from any bugs.

16. Empty the posts/pages trash

The trash is emptied every 30 days by default. You can change that time by adding this function to your functions.php file:

//empty WordPress trash once a week
define('EMPTY_TRASH_DAYS', 7);

Or change the number to 0 to disable automatically emptying the trash at all.

17. WordPress permalinks

One of the biggest neglected performance hits by advanced users is the way you set up your permalinks. There has been much discussion and it has been demonstrated that you should not just use /%postname%/ as your Permalink structure. I personally use /%post_id%/%postname%/ as it’s the fastest query (the Post ID is a primary key in MySQL).

18. Remove non-changing dynamic code

PHP functions such as <?php bloginfo('title'); ?> or <?php if ( function_exists('my_plugin') ) ?> nearly always output the same value so it doesn’t make sense to request it all the time increasing server load. Replacing those with its static content will decrease avoidable queries. To see how many queries a page load does you can use this code: <?php echo get_num_queries();?> .

19. Enable the default WordPress Object Cache

If you are using a cache plugin such as WP Super Cache, W3 Total Cache or WP-Cache you should ignore this step.

Since WordPress 2.0 there is a feature called Object Cache which is not enabled by default. To enable it follow these steps:

  • Open wp-config.php in your WordPress root folder
  • Add the following code:
    define('ENABLE_CACHE', TRUE);
  • Create a new folder called cache to store all the cached files in wp-content
  • Change the cache folder permission to 755 or 777

You can set an expiration time to keep it clean, to do this add this line too (time is in seconds):

define('CACHE_EXPIRATION_TIME', 3600); // 1 hour

20. Move your WordPress installation to a subdirectory

It will help keep the web server root folder cleaner. To do this you will need to do some tweaks in your website’s administration panel or in Apache so that the destination of your domain points to the /wordpress/ folder.

21. Fix PHP notices and warnings

The plugins and theme you are using work fine, if not you would disable them. But occasionally some of them are not coded a 100% correctly. One of the most common issues is not defining variables in PHP, this is not just a bad coding practice but it also makes the PHP engine go a bit crazy and take extra time to process the code. It is very easy to fix and any beginner programmer should be able to manage this. Once you are done, notify the plugin/theme authors of these so they fix the warnings and notices on the next release. Enable WP_DEBUG in your wp-config.php file and read this article on PHP error suppression performance.

Further tips

22. Change your hosting provider

I’ve got invites for a free bank transfer!

One of the main reasons why websites load slowly and sluggish is because of the hosting provider. Some hostings such as GoDaddy have really bad reputation and you should move to somewhere else like HostGator, you may spend £2-10 more per month but both your users and Google will compensate you.

Final notes

Here we’ve just covered optimizing a WordPress installation although you can keep optimizing the PHP code, MySQL queries, use less HTML, optimize the CSS selectors and use a sprite map, tailor Apache to your needs, enable Gzip compression to your files or use a Content Delivery Network amongst many others.

Free 100% online banking account

💳 Get your free debit Mastercard

4 comments

  • Seth says:

    Good ! this can help a lot! there are lots of codes I’m not familiar with yet thanks for your post cause it helps me handle my site better. Thanks keep posting. :)

  • James says:

    This is actually the best list of tips to tidy up a running WordPress installation. all queries worked perfectly and didn’t screw up anything (just changed the “wp_” prefix on the tables).

    As per my benchmarks I’ve saved 45MB of DB space and now pages load 100ms faster!

    amazing stuff dude

  • Neil from Beachwood says:

    Use the “optimize database” and “quick cache” plugins. Both will increase your speed.

    For database and file system backups, try the “WP Move” plugin. Although its primary purpose is to update the database when you change servers or domains, the standalone backup manager that comes with it is enough reason to install it.

  • Carol says:

    Would you suggest a nice theme for fitandbeauties dot com? I would love to hear expert advices. Its a blog about fitness and beauty!

Treasure Chest

Get notified of new projects I make
Usually one email every 3 months

Follow me for cool new products and interesting findings on graphic design, web development, marketing, startups, life and humor.


/*Twitter*/ !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); /*Facebook (function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=28624667607";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));*/ /*Google+*/ window.___gcfg = {lang: 'en-GB'};(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = 'https://apis.google.com/js/plusone.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();