14 Tips for Maximum WordPress Performance & Speed

The tips in this post are specific to WordPress. Before tackling the tips here, I advice you to implement as many related tips from my previous post. The previous post constitutes the foundation for this tutorial.

It is obvious, everyone hates a slow Website. Performance is a key factor for any successful Website including WordPress. Optimizing your WordPress Website for speed is not an easy process, it takes time to properly and safely make the changes. But before starting with any thing, make a full back up of your WordPress Website, this can be done by using the export function in your WordPress admin area.

How can you make your WordPress load faster? If you implement some of the tips outlined below, you will notice a dramatic improvement to your WordPress Website’s performance. Here are the tips and tricks that can be used to speed up WordPress and boost it’s performance.

Tools that Determine Website Speed

Run some of these tools prior to applying any of the speed/performance tips here in order to get a baseline metrics. Then make another run after implementing some of the tips below in order to measure the speed gain obtained.

  1. Website Speed and Performance
  2. Webpage Analyzer
  3. Google Page Speed – Mozilla Firefox plugin
  4. Yahoo! Yslow – Mozilla Firefox plugin
  5. Best Free Online Tools to Measure Website Speed

Tip0. Get a Fast Dedicated Web Server for Your Database

I added this tip on March 1, 2011. I felt that this is a very important tip, for you to seriously consider. From my own experience, whatever you do to make your dynamic Website load faster, if it is served slow, then there is not much you can do. In other words, if your database resides in a slow shared Web server then regardless how much you optimize your dynamic Website, it will still be slower than the average and you will not reap the benefits of your hard work.

How would I know if my database is hosted on a slow Web server? You can tell by the performance of your WordPress Website, your phpMyAdmin Web interface, and your WordPress dashboard. If these 3 are slow, sluggish and sometimes unresponsive, then what´s the common denominator between those three? you guessed it, your MySQL database. It is time to move your MySQL database to a much faster dedicated Web server.

Today, after the MySQL database of this blog has been migrated to a much faster and dedicated Web server, suddenly this blog loads in less than 2 seconds, which is 5-15 times improvement in load speed. Also my phpMyAdmin and my WordPress admin area are now very fast and responsive to user requests. So, if you implement all the tips below and you still not happy with your Website´s performance ask your web hosting company to move your database to a dedicated MySQL server. Believe me, you will be glad you asked.

Tip1. Keep WordPress Up to Date

You should always have the latest stable version of WordPress. Upgrading to the latest version is necessary because upgrades usually include performance and security enhancements and also new features. Go and upgrade to the latest version.

Tip2. Your Theme´s Choice

Choose a simple, minimalist theme for a faster load time. Choose a theme with a right sidebar which helps to load the content first. The theme should be well coded, valid for Web standards and accessible. Avoid themes that use excessive JavaScript or images.

If you think that your existing theme is slowing down your Website, revert to the WordPress default theme and test for speed. In this case you eliminate that your existing theme is not the culprit.

Tip3. Clean up Your Theme. Reduce the Number of Database Calls

In general, for each Web page, WordPress does the following:

  1. Compile the PHP code. More…
  2. Query the MySQL database.
  3. Create the static HTML file.
  4. Send back the HTML page to the browser.
  5. The browser, through HTTP requests, fetches all necessary components (JavaScript, CSS, images, Flash etc.) and displays the page.

#2 is a major cause of a slow WordPress Website: reading all the information needed from the database. This is where this tip comes into play.

Database calls is what makes WordPress dynamic. Reducing the number of database queries will lessen your server load and also speed up your Website. This is done by swapping dynamic properties with static ones. All WordPress themes include generic PHP code that can be easily replaced with static HTML tags.

Open the header.php file located in your current theme folder. What we need to do is replace some of the dynamic content with hardcoded static content. Since there is no reason for the theme to be portable anymore, we can replace those PHP queries with their corresponding static HTML code. For instance:

//In the header.php file. You could replace the 5 dynamic statements:
   <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
   <meta http-equiv="Content-Type" content="<?php bloginfo('html_type');?>; charset=<?php bloginfo('charset');?>" />
   <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
   <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
   <link rel="shortcut icon" type="image/x-icon" href="<?bloginfo('template_directory'); ?>/images/favicon.ico" />

//With the corresponding static ones that do not require database queries:
   <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link rel="pingback" href="http://bacsoftwareconsulting.com/blog/xmlrpc.php" />
   <link rel="stylesheet" href="http://bacsoftwareconsulting.com/blog/wp-content/themes/indezinerpaperwall/style.css" type="text/css" media="screen" />
   <link rel="shortcut icon" type="image/x-icon" href="http://bacsoftwareconsulting.com/blog/wp-content/themes/indezinerpaperwall/images/favicon.ico" />

//If it exists, remove this statement for security reasons:
   <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" />  

//Do not modify the title tag since wp_title() varies depending on what post/page is being viewed:
   <title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>

You can also check for similar queries in the footer.php and replace them.

The best way to exactly know what you need to replace, is to compare your dynamic code at header.php and footer.php with your HTML source file.

Tip4. Become a Plugin Minimalist & Upgrade Current Ones

Plugins have tremendous advantages: they save a lot of time in coding and add a lot of functionality to your Website. However, I want to caution you about adding unnecessary plugins to your Website. Most plugins add a lot of extraneous code, and even create records in your WordPress database, thus increasing the load time of your Website.

Reducing the Number of plugins is one of the easiest tips to reduce your Website´s load time. Why? One reason is not all plugins are coded to load only when they are actually needed on the page. Ask yourself whether a plugin adds value to your Website. If it does keep it, otherwise delete it. Also make sure that you are using the latest version of the remaining plugins.

Did you know! You can just replace the functionality of many plugins by directly adding the code to your theme.

References:

Tip5. Install a Caching Plugin

Caching drastically eases the stress on your server by saving and displaying static files for your visitors instead of making numerous queries to the database. This greatly reduces your Website´s load time.

There are several plugins to choose from, the most popular are listed below. My preference goes with the W3 Total Cache as it combines not only page caching, but also browser caching, database caching, object caching, compression, minification and CDN integration. But don´t take my word for it, feel free to try the other caching plugins and see what works best for your Website.

References:

Did you know!

  1. If you are already using PHP speedy make sure to remove it prior to installing any of the caching plugins I mentioned above. PHP speedy can cause conflict with caching plugins. In my opinion a caching plugin far outweigh the benefits of PHP speedy. Caching plugin is a better choice and PHP speedy already passed its useful life.
  2. It takes time and effort to properly configure W3 Total cache because of the many options available. But one nice feature about it is that you don´t need an additional database caching plugin.
  3. If you decided to use the Hyper Cache plugin, also use with it the DB Cache Reloaded plugin, they complement each other and you will get a nice boost in performance.

Tip6. WordPress Trash Feature

In WordPress 2.9 and above, there is a Trash” feature added to the core code. This feature works like the recycling bin. A deleted post goes to the trash bin first. The bad thing is that you have to empty the trash regularly, otherwise your database gets bloated. By default the trash automatically empties every 30 days. You can modify that by adding the following line of code in your wp-config.php file located in the root directory:

//Empty the trash every 7 days
define('EMPTY_TRASH_DAYS', 7 ); 

Another method is to manually and regularly empty the trash from the WordPress admin area. Also, while you´re there, empty any spam comments too. Unfortunately, there is no constant that can be added to the wp-config.php file which automatically empties the spam (like: EMPTY_SPAM_DAYS). You still need to manually delete your spam comments from the WordPress admin area. Like trashed files, spam comments can take up some serious database space that need to be deleted on a regular basis.

Important! never use a Word processor like Microsoft Word for editing WordPress files but a text editor like Notepad.

Tip7. Disable Revision Feature & Delete Existing Revisions

WordPress 2.6 and above has a new feature which is post and page revision. WordPress automatically creates revisions of your posts or pages. Whenever you save a post or a page, the old version is retained so you can revert back at any time. Older revisions are never deleted so you always have a full history of all changes. However, this feature causes your WordPress database to rapidly increase in size. Depending how active your blog is, revisions can seriously bloat your database with multiple copies of the same post. Too many revisions stored in the database might cause longer query time and a slower loading blog.

Reference:

Tip8. Flush the Buffer

When using the PHP flush function, you will slightly improve the speed of your WordPress Website. When users request a Web page, it can take up to 0.5 second for the server to display the HTML page. During this time the browser remains idle. The flush() function helps loading the partially ready HTML to the browser, while the server is busy with the rest of the content.

To insert the flush() function in your WordPress code, open the header.php file located in your theme´s folder and insert the single line of code immediately after the </head> tag.

</head>
<?php flush(); ?> //insert immediately after the head tag

If you use W3 Total Cache plugin in your Website, it is probably safer not to use the flush() function. I was using them both for several weeks and everything was working fine with no issues, but I decided to remove the flush() function just to be safe. I am not sure about the compatibility of the flush() function with other caching plugins.

This is from W3 Total Cache FAQ page: I see garbage characters instead of the normal Website, what´s going on here?
If a theme use the call php_flush() or function flush(), that will interfere with the plugin normal operation; making the plugin send cached files before essential operations have finished. The flush() call is no longer necessary and should be removed.

Tip9. Optimize your Database From phpMyAdmin

MySQL database does not clean itself up. Optimizing the database is an important step to speed up your Website. To optimize your database, you can either do this manually or use a plugin. I prefer manually, and no need for unnecessary plugins. To do this manually, log into phpMyAdmin. Find your WordPress database tables and select all of them. At the center bottom, click “Optimize table” from the drop down menu.

Optimize MySQL database from phpMyAdmin to make it faster.

ALWAYS backup your database before executing any SQL commands. You can create a backup copy of your database from phpMyAdmin with the Export function.

If you suspect a corrupt database first select “Repair table” then “Optimize table”.

If you don’t want to do this manually then this plugin is compatible with the latest version of WordPress (version 3.0.5): DB-Optimize

Afterwards, since you´re there …
After you deleted all unnecessary plugins and unused themes, there is a good chance that there are still orphaned data in your WordPress database. All plugins and themes use the wp_options table to store data. When you delete a plugin or a theme, some records are left behind. To clean these orphaned data, select the wp_options table and then the Browse option. Then go through the wp_options table record by record and delete any records that are left behind. Usually every record can be easily associated with a plugin or a theme.

I am assuming that you kept the WordPress table prefix as wp_. wp_ is the default but it can be changed to give your WordPress Website added security.

Tip10. Check For Exploits

Malicious code can seriously cripple your Website’s performance. If you notice a sudden increase in your Website’s loading time, it is worth checking for possible malicious injections. I suggest that you install one of the two plugins listed below and run a scan, after that you can remove it.

References:

Tip11. Split Comments Into Several Pages

If you are getting lot’s of comments on your blog then it makes sense to split the comments into several pages in order to increase your page loading speed. This can be done from your WordPress admin panel by going into Settings -> Discussion. There is an option Break Comments into Pages with …, where you can set the number of comments per page. Also, you probably already know this, delete all comments that don´t add value to your post.

Tip12. Cache Gravatars

Gravatars are very slow to load. Every gravatar image is a new HTTP request. A page with 100 comments would have 100 additional HTTP requests, which cause a major slow down to your Web page.

If “Show Avatar” is enabled in your WordPress Admin area AND you are getting lot’s of comments then it makes sense to cache them locally.

One solution to speed up the page load time is to create a local gravatar cache, where images are cached and served from your server instead of the gravatar server. To do this you can use the Gravatar Cache Plugin. A second better solution would be to disable Avatars.

References:

Practical Tips! (From your WordPress admin area: Settings -> Discussions)

  1. If you can afford it, don´t show Avatars.
  2. If not, set your default Avatar to Blank or to a custom avatar located on your server.

Unrelated but it helps! From your WordPress admin area: Settings -> Writing; keep Unchecked the option: Convert emoticons like :-) and :-P to graphics on display

Tip13. Use Excerpts and Limit the Number of Posts Displayed on the Main Page

Never show full posts in the main page. Let´s say you have 5 posts in your main page, and by showing every post in full, then it will take long time for the page to load. One way to reduce page load time, is to use the_excerpt() function.

Open the index.php file located in your theme folder and replace the the_content() function with the the_excerpt() function. Also you could do the same for archive.php and search.php files. (DO NOT TOUCH page.php or single.php files.)

//The '...' can be anything inside. 
//Search and Replace the_content() function
<?php the_content('...'); ?>

//With the the_excerpt() function
<?php the_excerpt('...'); ?>

Now the second step is to limit the number of posts being displayed on your main page. You can do that in the WordPress admin panel under: Settings -> Reading: as shown in the image below:

Post count on main Blog page from the WordPress Admin area.

Tip14. Split Long Posts into Several Pages

If you have a very long post, then it is best that you split the post into several pages. In this case each page will load much faster. Assuming that your theme supports it, all what you have to do is add the following quicktag in your post where you want the split to occur:

<!--nextpage-->

Where to check if the theme supports splitting the post into several pages? First you could add the <!--nextpage--> quicktag at the location where you want to split the post and see if it works. Also you should see something similar to the following code in your page.php, single.php and depending on your theme in either index.php or loop.php files . All these files are located in your theme folder. If you can´t find the wp_link_pages() function, then your theme does not support splitting the post into several pages. But you could always add this functionality into your theme.

//Something similar to this line of code should be in <em>page.php</em>, <em>single.php</em>, and <em>index.php</em> (or <em>loop.php</em>) files:
<?php wp_link_pages(array('before' => '<p><span class="strong">Pages:</span> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

Some WordPress themes like Twenty Ten have an additional file called loop.php

Reference:

Conclusion

That should do it for now. Hopefully, a few of these tips will help make your WordPress Website loads much faster and with maximum performance. If you know of more tips to speed up WordPress, please share it in the comment section.

If you enjoyed this post, please consider: linking back to it, subscribing by email to future posts, or subscribing to the RSS feed to have new articles delivered to your feed reader. Thanks!

About the Author |
Boutros is a professional Drupal & WordPress developer, Web developer, Web designer, Software Engineer and Blogger. He strives for pixel perfect design, clean robust code, and user-friendly interface. If you have a project in mind and like his work, feel free to contact him. Connect with Boutros on Twitter, and LinkedIn.
Visit Boutros AbiChedid Website.

23 Responses to “14 Tips for Maximum WordPress Performance & Speed”

  1. King says:

    It is also advisable to review the plugins from time to time by scanning them with P3 Plugin which tells us about the load of the plugins that we installed in WP.. it helps us to review and check if we can get rid of them by adding few lines of code..