Speed up WordPress, and clean it up too!
Every once in a while people will ask me to fix their blog, because it's either slow, or broken. When it's not something to do with their WordPress hosting, (some hosts are just plain bad and slow), most of the time this is caused by either broken plugins, or broken themes. There are a few things I tend to do when I get to clean up stuff, and I though I'd list them for you.
Clean up your theme
header.php
First of all, what I do is make the header.php file do a lot less queries. Because themes have to be easy to spread, they have to get almost all the blog specific info from the database. That results in a lot of queries for stuff that you could just hardcode into the theme. Some examples, taken from the default kubrick theme:
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content=" <?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
Could just as well be:
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
You can also:
- make your stylesheet URL's static
- make your pingback URL static
- make your feed URL's static
- you can remove the blog's WordPress version
- make your blog's name and tagline / description static
Doing all that, you can remove 11 queries to the database, and this can highly speed up your theme.
footer.php
The default theme also has some of these calls to the database in the footer which you can make static, or remove altogether:
- your blog's name
- RSS feed URL
- Comment RSS feed URL
You can also remove all comments that aren't necessary, like "If you'd like to support WordPress, having the "powered by" link somewhere on your blog is the best way; it's our only promotion or advertising." I can tell you that that line is in a LOT of footers, and it's a waist of bandwidth once you have decided to leave the link for WordPress in or not.
Check your coding habits
You will have added code to your themes for your plugins. Let's say you have a line of code like the one below, for a plugin that thanks people coming from search engines:
<?php refer_thanks(); ?>
This creates a problem, as soon as you, by accident or another cause, disable the plugin that holds the refer_thanks function. When the function doesn't exist, the code errors out, and your page doesn't continue to load, thereby breaking your blog. To fix this, PHP offers a special function called function_exists, and using it, the code would look like this:
<?php if (function_exists('refer_thanks')) { refer_thanks(); } ?>
Now, if the function doesn't exist, your theme, and thus your blog, won't break. It's probably a good idea to do this for every line of code you added for a plugin.
Install a caching plugin
Lastly, you should really consider installing either WP-Cache, or WP-Super-Cache. They make your blog so much faster, that you won't know what happened to you once you've got them running.
All of this makes sure your blog remains maintainable, and fast.






These are great tips Joost. Especially important for preparing for any traffic spikes as well.
Some great tips! never thought of hard coding the header values, going to try that now, thanks :)
Excellent tips. I'd covered most of those but had overlooked the meta "text/html; charset=UTF-8" reference. Fixed that now and blogs are loading 2 ns faster ;-)
db
If you are using caching, is it still necessary to remove all the queries from the header and footer? It seems like they'd be queried once to generate the cached version of the page and then the cache would hit after that.
@Gyutae Park: yup, very true.
@Adam Dempsey: yeah it's weird, hardly anybody seems to do that.
@David: hey, it's the small things ;)
@Luke: well, every comment invalidates (iow clears) your cache, so I'd do both.
Excellent suggestions :-) I have used it to adapt my blog's theme and even some of the plugins too. Every small improvement of loading time helps.
Be careful with the cache option. Some results will change when implemented. For example: Most Popular will no longer reflect accurate results. The pages are now cached and therefore will not update the database with each hit.
Good post. Speeding up improves user experience, which is important.
Joost, about the theme and UTF-8. With this encoding, the characters won't be showed correctly. If you're using < MySQl 5, MySQL uses default ISO-8859(-1 ?). The solution is the use of extra queries to change the character encoding.
Hmm Hendrik, that's a nice point... In most cases, WordPress set's it to UTF-8. Are you suggesting that setting either MySQL to UTF-8 or the blog to ISO-8859 would speed things up?
And btw, ISO-8859 and ISO-8859-1 don't support the € character... So it should be ISO-8850-15 ;)
@Scooter: the question is: do you care about the popular posts being completely correct all the time?
Joost, you're wrong ;)
UTF-8 doesn't support €. ISO-8859 en ISO 8859-1 work fine.
My exprience with UTF-8 is wrong:
- MySQL
- .htaccess
- PHP headers
- Meta characterset
After converting to UTF-8, symbols as € (will be a square), ë, é, etc. This characters will be convert to strange characters. Currently, I use ISO-8859-1. That works fine for European content.
Thanks for the tips Joost. I used to use wp-cache, but found my self always turning it off and then on again durring development. Now I have put in a development server this shouldn't be a problem and I can confirm that when running it really did make the site faster. I like your other tips to reduce database access, but with cp-cache, is this not elliminated anyhow?
Cheers,
Allan
@Hendrik: I'll dive into it tonight, you're effectively saying that putting it into ISO-8859-1 is easier and faster, sounds good ;)
@Allan: it does when you're serving a cached page, however, each comment invalidates that cached page... I'd do both.
I don't remember the specific post, but it was only like a week ago that Matt Cutts suggested removing the Wordpress Version tag to cut down on hacking attacks so that's definitely an important one to remember. If hackers can easily find out what version of Wordpress your running, especially if it's an older version, then it makes hacking all that much easier.
Thanks for the tipps.. You are right, with some work it might be possible to speed up wordpress, and with every new plugin mine gets slower and slower..
i will really need to check my code if i find time..
Tnx for the tips Joost, hope this will stop my blog from changing themes all the time.
By the way, the post Kyle is refering to is this one: http://www.mattcutts.com/blog/three-tips-to-protect-your-wordpress-installation/
@Kyle & Ruud: read it too, read Matt's blog daily, of course ;)
Yeah, thanks for the tips, my blog changes themes often to. Maybe a few tweaks will get it to work. As a web designer I have found a lot of problems with wordpress and speed is one of the main issues in complicated sites. Thanks.
These are some great tips. I'll have to look into implementing some of them, especially when I start generating more traffic.
Hi Joost, nice post, thank you. In my blog, the UTF-8 works great, the same with the Euro sign. can't see any problems.
Hi,
i think you should also take care with commands, tag cloud and similar posts. tha last one´s are plugins that use many requests.
Sorry if this is off-topic, but since we're talking about optimization here such as caching, it sparks a recent question that I have.
I was reading about your Google Analytics plugin and it seemed that one of the selling points was that it was running mostly on the server-side. I don't question the benefits, but I was wondering what happens when you run it with a caching plugin such as WP-Super-Cache. Is it safe to run your analytics plugin with super cache or does the cache interfere with it?
The reduction of queries makes total sense - thanks for even more tips!
Thank you. Just what i needed. A guide to clean up my Wordpress blog. I have lots of old plugins and themes, maybe it's time to delete some of them.
Thanks much to do...great feed
Great, simple tips. I just went through and changed the header files of my blogs to use the static info, and it really did speed up the loading time significantly. As always, you are a font of great info. Thanks.
good tips, as long you don't want to migrate your modified theme to another site...
A simple way to hardcode is to check the source-code of your site and copy and paste the entries in header and footer. Like this you take whatever charset your blog suggested with the language attributes requested and the correct path to the stylesheet etc.
(don't do this thing with index.php as that should really be generated new...)
thanks, Joern
I'm googling on how to fix a broken theme and I found this site. Thanks for the tip although I did not get it the first but after several tries it's already done.
-Jan
Great article. I had a lot of jargon lounging around my wordpress blog...old themes and plugins.
This really helped me clean it up :) Thank you so much.
Where's the plugin that will transform every post into quality linkbait and submit to all of the top tier social networks? :-)
Hello, i can´t see the lines of code that haev to be change on the headerç
PD: sorry for my bad english, i'm from Argentina
I guess there is some problem with your code tag. Some of the code in the article are not displaying properly.
Thx for noticing Sudar, fixed.
My question is, how do you tell what each php code represents, so you can replace it with hard coded values?
For example, is replaced with "UTF-8"
How do you check what charset is being used to know how to replace the php tag with a static one?
There are others as well, for example:
="
etc.
Thanks!
Sorry folks I figured it out. I just loaded the page and viewed the page source to see what the code was being converted to. Then I just pasted that into the header.php.
Thanks!
--JP
Very comprehensive, thank-you. One point of concern for me: I have never seen any benefits from any type of cache plugin. In every case my sites are always slow to load the first time and only then, do pages load faster. This is no good for first time visitors and only serves regulars. Is this a typical cache behaviour? if not what could I be doing that's wrong. To my mind, the first hit must be the fastest as this is the visit that gets you hooked or gets aborted for slow loads.
Nice tips. You can speed up WordPress even more if you turn on MySQL and PHP caching. I made same benchmarking on fresh WordPress installation (no modules and empty database) and the gain was about 150%. I used ab (Apache benchmarking tool) and document all on my site. Next step will be to install WordPress caching module and make WordPress fly :)
I have changed all the header links to static after reading this article, and installed wp-cache, now the site is loading much much faster.
Thanks for the sharing.
@Sudar:
It usually is just something simple. Take a moment to double check it all then try it again.
It really doesn't help it load much faster and is well worth the time spent.
a tip from http://www.dailyblogtips.com/remove-the-hyperlink-from-single-post-titles/
some more tuning tips inside the blog - great informations
Hi,
Nice tips thanks for the info. Can you please give tell me about the tip, Is it good to use blog catalog or topblogger buttons for my site http://www.localsadda.com I want to implement can you tell me more if you have any info..
Your tips are great! Thank you so much for taking the time to post them and help people such as myself clean up our blogs, make them faster nad user friendly!
Cheers!
Jess
Can you provide your goods and services into the educational sector in your area. if you can and you are willing to offer the schools a discount, you could find your business in front of all the educational establishments in the uk. you also get direct communication with headteachers to update them with your special offers etc
Nice tips. I am using Wp_Cache since a long time and it works!
I had a good laugh the other day. I work between an online blog and a test bed I use for blog development.
I recently downloaded several files from my online blog to the test bed I use for blog development. I did this in order to insure that the files, including style.css, were identical at both locations.
However, I had forgotten that I had made the links in the online header.php file static.
I did not notice this for a frustrating day or two. I tried to make several styling changes in my local copy of style.css—but the changes never made it to my browser's display!
Eventually, I noticed that the browser was not looking at the style.css file on my test bed but was always retrieving the stylesheet from my online blog. Once I discovered this and corrected the header.php file to show the right link to my local stylesheet, the changes began to alter the HTML display as expected.
It is not out-of-date information? Because I have other data on this theme. http://video-online-go.ru/map.html
Spam ^
Anyway, I needed to leave a reply somewhere to see your relish plugin at work. Ignore this message.
Very nice information.i am looking for this for long time.i bookmarked your blog ,Thanks for this.
I took a look at my blogs database and noticed that wordpress creates "revision" rows for every post every time I edit a post. I think that removing this "revision" rows will also help, specially blogs with 1000's of posts, speed up queries since there will be less records in which to look for.
@MiguelAvarez - The Revision Control Plugin can really help if you want to limit or disable the number of revisions.
Hey thanks alot for the write up. I have been searching for awhile for this information and have been unable to find a write up this comprehensive. I have alot of work to do on my older sites with the clean up and have experienced alot of errors with it but hopefully this helps. thanks again
Useful tips for speed up wordpress blog, i use WP-Super-Cache as my chace plugin, i installed this plugin i see my blog seems more even faster than before...
Thanks for the tips
Some great tips. I have also gone to http://validator.w3.org/ to see what can be fixed. Looks like I am finally going to have to learn code :-)
I prefer to set the meta tags static (maby a little bit work, but hey who cares!).
Thanks for the post!
-- Youri ( devfolio )
Thanks, oh my god that was so needed. A thing to clean all my dirty plugins. Sweet!
I currently have a blog with 6,290 pages. Once I created this many pages it slowed down so much that it about to hang up the idea of using wordpress to manage my site. Any suggestions to speed this aside from your mentionings above?
wordpress by itself scales fairly well. The real problem comes when install plugins that add queries to a post before the page is rendered. Typical plugins are related post plugins. The more posts you have the more CPU work is required building a related posts list before the page is rendered. If you are using any plugin that needs to query all your posts before spitting out content, you should consider removing these, or using an alternative that caches results. YARPP does use cacheing for its related posts, so this may be a useful alternative.
There are many other things to look at both in design and server side ... really beyond the scope of a short comment.
Thanks for this.
very helpful informations for seed up wp, thanks a lot..
Nice article! I've implemented your tips on header.php, hoping for some speedup :)
Thank you very much for your good sharing.
Okay, this may be one of those its late & im not thinking clearly kinda questions but why would you not add lang="en" (or whatever language is appropriate) to the html tag? Before you "cleaned it up" it declared the language but once it was "cleaned" it didn't or am i missing something? Just curious! Great post!! :D
There is a special plugin for Wordpress - Web Optimizer, http://wordpress.org/extend/plugins/web-optimizer/ - that can increase client side load speed oy your weblog on Wordpress by 200-500% in one click.
Excellent tipps in this case... but sunnybear whate exactly is this script ?
Thank you for the Tipps =)
Cheers for the tip about Web Optimser I've been looking for a solution to this all day.
Thanks for the tips. I like it!
Web Penghasil Duit
Excellent tips, I used it :) Thanks
Excelent Tips man, thanks
Excellent tips... is there any suggestion about html compression.
Brillaint tips this was really really helpful
thanks
Matt