38 ways to optimize and speed up your WordPress blog

WordPress blogs and sites can be notoriously slow. But fear not – here are ways to make your WordPress blog super speedy and fun for your visitors to view with a few tweaks, hacks and plugins. Be sure to check back because I will be updating this post as I discover new and wonderful ways to optimize and speed up WordPress blogs.

[This post is in honor of the current Pessach (Passover) season, a Jewish holiday where we clean our houses frantically in the hope that not one crumb of leavened bread (i.e. regular bread) be found during the 7 day holiday. This post is the WordPress version of Pessach cleaning, where cluttered databases are equivalent to leavened bread, etc. Happy Pessach!]

Define goals and create benchmarks:

First, define a goal, such as reducing page load time from 8 seconds to 2 seconds.

Measure your initial state and the results of each modification so that you can quantify any improvement. Test your site’s speed with the Website Speed Test, but do multiple tests since the results can be inaccurate due to fluctuations in your internet connection and other factors.

Use Pingdom to get a detailed analysis of your blog’s loading time and performance.

YSlow – analyzes web pages and tells you why they’re slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with Firebug. See this presentation from Yahoo! that covers their latest research results and performance breakthroughs. It covers their existing 14 rules, plus 20 new rules for faster web pages. They’ve categorized the optimizations into: server, content, cookie, JavaScript, CSS, images, and mobile.

Reduce the number of dynamic PHP and http calls:

“There is an inherent overhead in each HTTP request. It takes substantially less time to serve one 30K file than it does three 10K files.” So combine all files in a type into a library. Learn how here.

Use different host names to increase the number of active download threads.

Minimize PHP and database queries – Each time a page on your site loads, if your browser has to execute any PHP queries, it adds to the load time. If you replace the PHP queries with static HTML, every time a page loads, your browser just reads the HTML. An example from WP Candy:
With PHP requests: <title><?php bloginfo(’name’); ?><?php bloginfo(’description’); ?></title>
Without PHP requests: <title>WPCandy - The Best of WordPress</title>
Joost de Valk says that you can remove 11 queries to the database by doing the following in your header.php and footer.php files:

making your stylesheet URL’s static

making your pingback URL static

making your feed URLs static

removing the blog’s WordPress version

making your blog’s name and tagline / description staticSee more examples of how you can replace code in your WordPress template files with static HTML here and here.

Check if you have too many external calls to things like Amazon, eBay, MyBlogLog, etc. Try commenting them out one by one to see if it speeds things up.

Optimize your files: CSS, HTML, Javascript, images, video

Consider hosting your images on an external site like flickr that has huge servers and can handle the load.

Use CSS sprites for static web images. CSS sprites are where the images are added to one larger image file, and laid out in a convenient way. Here’s a CSS Sprites generator.

Do not host videos on your server. Upload them to YouTube, Google Video, or any other video sharing site and let them handle the server load.

Compress your Javascript, using a tool or by removing formatting (and potentially by shortening function and variable names). This can reduce file size by 60%. Add gzip compression to that as well and you’re looking at a serious size reduction.

Compress your CSS with the CSS Compress WordPress plugin – Automatically removes comments, new lines, tabs, and gzip compresses (GZIP) any CSS file called with “<?php bloginfo(‘stylesheet_url’); ?>” Just activating the plugin with the default Kubrick theme will reduce the CSS file from 8k to 1.7k.

Use external scripts – Instead of placing tons of code in your header.php file, use external scripts. This allows the browser to cache the script so it won’t have to read it for every other page.

Validate your code at W3C to make sure you don’t have any major errors slowing down your page.

Allow progressive rendering: Load CSS files at the top of the page, from within the head section; load JavaScript files at the bottom of the HTML. And/Or…

Stop slow loading scripts from breaking your blog with IFrameWidgets v1.0 WordPress plugin. Slow widgets or snippets of Javascript can either time-out, or prevent the items below them from loading. The plugin creates WordPress sidebar widgets that run in an IFrame. Since IFrames load in parallel to the rest of the page, slow loading JavaScript widgets won’t affect the rest of the page.

Plugins

Disable or delete unused plugins – some plugins have tons of script and code, and even create database tables in your WordPress database. Use only the plugins you really need, and delete the rest.

Sometimes plugins require that you add a snippet of code to your theme’s template files to call the plugin. Usually, it looks something like this:
< ?php refer_plugin(); ?>
However, if for some reason you disable that plugin, you will get an error. Joost de Valk recommends using PHP’s special function called function_exists to prevent the blog from breaking if plugins are disabled or removed. Using it will make the code look like this:
< ?php if (function_exists(‘refer_thanks’)) { refer_thanks(); } ?>

Control when your WordPress plugins are loaded: WordPress processes all of the code for all active plugins, even if that plugin isn’t used on a particular page. If a particular resource heavy plugin isn’t used on certain pages, then you can tell WordPress not to load it on those pages by wrapping an if statement around the content of each function to check what page is being loaded. Learn more about how to do this here and here.

Database

Use phpMyAdmin to optimize your database: Log in to phpMyAdmin, select all the tables, and then “repair” and “optimize.”

Delete excess records in your WordPress database. All plugins use the wp_options table to store data, which is the same table used by WordPress to store all settings for your blog, and is accessed every time you open any page. When you deactivate a plugin, these records are left behind, bloating your database. To clean it up you can use the WordPress Clean Options Plugin, which finds orphaned options left after you have removed plugins and removes them from the wp_options table, or manually as follows: Back up your database, login to phpMyAdmin, open your blog’s database, and click on browser for the wp_options table. Go through this table record by record to identify any records left behind by old plugins. (from WordPress Web 2.0 Spot-Er).

Caching and protecting for server overload

WP-Cache 2 – caches Worpress pages and stores them in a static file for serving future requests directly from the file rather than loading and compiling the whole PHP code and then building the page from the database.

WP Super Cache – This plugin is a fork of the WP-Cache 2 plugin, and generates html files which are served without ever invoking a single line of PHP.

PHP Speedy – PHP Speedy is a script that you can install on your web server to automatically speed up the download time of your web pages.

Use the Expires and cache-control max age headers for all pages; Make dynamic pages support the if-modified-since request header; Use far future expiry headers on static resources; Use the cacheability engine to test that you have caching and validation set up correctly. If you don’t know what all this means, don’t worry, neither do I, but you can find out more here.

Digg Protector plugin – The Digg Protector will determine if a visitor is from Digg, and if the visitor is indeed from Digg, the plugin will serve them a remotely-hosted version of the image. Otherwise, the plugin will serve the locally-hosted (on that server) image.

Share:

About Miriam Schwab: Miriam is the friendly CEO of illuminea, a WordPress design and development agency. Miriam is a huge fan of WordPress and has been using it for over five years now. In addition, Miriam and her team have been organizing the local Israeli WordCamp conferences for the past few years. View author profile.

This is an extremely useful post. My MMO wordpress blog loads pretty fast but I have other blog themes that don’t and I didn’t understand why. I am sure this post has everything I need to get them sped up a bit.

Great article. Quick question though, if I’m using wp super cache, do I need to do all those changes with the PHP calls as well? Aren’t the pages cached with the super cache and therefore the php isn’t being called?
In other words will it dramatically speed things up even thought the pages are cached?

Marina – The caching plugins generate the HTML based on the PHP every time something changes on your site, so you can’t remove them. Without the PHP, there would be nothing to create the HTML! When caching is used, the HTML is stored, whereas when it is not on, the PHP generates the HTML every time the page loads.
Also, (I think) they dynamically generate the page for anyone who is logged in or who has recently commented on your site.

Thank you for an extremely helpful article! I’m only beginning to touch the iceberg by following the suggestions from step 1! However, I do have an issue at the moment with a 2.3.3 site that I run, because WP-Cache2 doesn’t seem to work on it (anymore?) so I’m now forced to turn on the default WP caching, as I’m not sure what effect SuperCache will have on the installation.

The WordPress Object Cache removed the file based portions of the code. Before you could enable and disable whether it wrote/read from a file instead of using the database. That part has been removed. The WordPress Object Cache is always on in 2.5, unless you replace it with another caching plugin.

[…] (yet useful) plugins/themes, it can put lot of load on the server when it comes to memory usage. Miriam has written an excellent post which gives you lot of ways through which you can optimize your WordPress blog and that will also […]

Thank you Miriam for taking the time to write such a wonderful guide for optimizing WordPress. I’ve recently installed the WP-Supercache plugin and its made a big difference in my performance. I had previously intalled a plugin called WP-Wall (similar to a Facebook type wall) and it caused my hosting company to shut down my site due to CPU overload. They suggested I install WP-Supercache and since my blog has been running much smoother. I will also follow your advice about deleting the plugins I am no longer using. This is something I hadn’t thought of.

Ash – You probably already realised this, but I just want to clarify something in case you have misunderstood.

You don’t need to delete plugins you aren’t using, you just need to delete plugins which are activated that you aren’t using. They don’t do any harm just sitting there, it’s only when you activate them that they become a problem as they start doing database calls, displaying random code in your pages etc.

hmm.. what is the best ways?? I mean i tried using WP-Cache it seems the same and not faster, and i changed to WP-super cache, i cant change the htaccess files as my server is shared among a few sites.. if i change, it cannot be opened so that means rewriting htaccess files cant be done, so basically what is the best way?

Great article. I’ve just started trying to reduce server load and decrease page load times because my webhost is trying to force me onto a dedicated server plan. I wrote an article about my experience here : http://codytaylor.org/2009/09/optimize-wordpress.html
Some feedback would be great

[…] website of mine. This is why I decided to write this blog post. No matter how much fun it is to update and tune up your website to look like perfection, the thing that really matters is content when it comes to getting organic […]

[…] 38 ways to optimize and speed up your WordPress blog | WP Garage WordPress blogs and sites can be notoriously slow. But fear not – here are ways to make your WordPress blog super speedy and fun for your visitors to view with a few tweaks, hacks and plugins. Be sure to check back because I will be updating this post as I discover new and wonderful ways to optimize and speed up WordPress blogs. […]

hi thanks for your great article. i tested my site with pingdom and am confused by the results. more than half of the load time is in the very first item and i’m not sure what that means.
here is the archived test: http://tools.pingdom.com/fpt/default.asp?url=http://todd.benivegna.com/&id=1760535
this seems to coincide with the fact that i noticed that there is a 2-3 second delay (sometimes 4-5) before anything loads, but once it loads, it loads fairly quick.

[…] posts on this topic:4 Simple Ways To Speed Up WordPress4+1 Ways To Speed Up WordPress With Caching38 ways to optimize and speed up your WordPress blogThe 3 Easiest Ways to Speed Up WordPress18 Useful Tricks To Speed Up WordPress & Boost […]

If your wordpress blog have images then you can also reduce them so that loading time cam be reduced. Also the above mentioned methods are great options provided you use them properly and according to your need.

[…] These 4 points listed above have made a huge difference in my experience, however they are just the start. If you’ve done the 4 things above and still want more speed, then I’d suggest looking at this article. […]

Good list. I wonder how many people realize how significant getting rid of the php in the header is; arguably as much of a difference as caching.
You missed a cache. It’s Quick cache and a one button push cache that speeds up my site as much as W3 Total Cache without going through all the convoluted steps. I use it in conjunction with WP-Minify, which is also an activate and go. Unlike other caches, these two are simple and don’t require the user to fool with all the files.

Great information here! Thanks for the various ways to speed up WP Blogs. I am a resller webhost and also put up blogs for businesses and did not have a resource I could go to for helping me with tweaking my blogs for my customers. I have several blogs not that have a load speed problem and with your tips and resources, I have been successful in improving my customer’s blog sites.

[…] There was the widows and orphans issue … load speed of your blog is really important. Not only is it frustrating to readers trying to read your post, but Google hates a slow site. And my blog periodically has load speed issues. After calling my host company, and then switching host companies, and then bugging them some more, I resorted to googling how to speed up my blog. WordPress Garage has an excellent post on 38 ways to Optimize and Speed Up Your Blog. […]

You have included some excellent points and tips that are sure to speed up anyone’s WordPress site. Have you ever tried CloudFlare? It’s a free CDN/DNS. I managed to half my sites load times using it. It’s also very easy it implement as it has its own plugin.

As for CloudFlare – I never tried it out because the idea of having all my site’s content being dependent on another service like that made me nervous. Plus, recently I’ve read about sites where CloudFlare not only didn’t speed things up, but slowed them down.