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.
- Website Speed and Performance
- Webpage Analyzer
- Google Page Speed – Mozilla Firefox plugin
- Yahoo! Yslow – Mozilla Firefox plugin
- 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
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:
- Compile the PHP code. More…
- Query the MySQL database.
- Create the static HTML file.
- Send back the HTML page to the browser.
#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:
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.
- Caution! Adding Plugins to Your WordPress Theme
- 20 WordPress theme Hacks to replace the need for Plugins
- Speed Up Your WordPress Blog by Having Less Plugins
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.
- Caching a Dynamic Website. Does it Make a Difference for Loading Speed?
- WP Super Cache Plugin
- Hyper Cache Plugin
- W3 total Cache Plugin
- What is the best WordPress Caching Plugin
- Use WP Super Cache for WordPress speed, not W3 Total Cache
Did you know!
- 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.
- 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.
- 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:
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.
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.
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.
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_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.
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.
Practical Tips! (From your WordPress admin area: Settings -> Discussions)
- If you can afford it, don´t show Avatars.
- 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
:-Pto 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
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.)
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:
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:
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.
Some WordPress themes like Twenty Ten have an additional file called loop.php
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.