Speed up and clean up your WordPress!
Every once in a while people will ask me to fix their blog, because it's either slow, or broken. 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.
Related posts
- Move your WordPress blog to a new domain in 10 steps!
- 10 Checks to the Perfect WordPress theme
- Improved WordPress Breadcrumbs
- 11 Top WordPress Plugins Every Blog Should Have
- Breadcrumbs in WordPress













Gyutae Park Jan 21st, 2008 at 18:18
These are great tips Joost. Especially important for preparing for any traffic spikes as well.
Adam Dempsey Jan 21st, 2008 at 18:21
Some great tips! never thought of hard coding the header values, going to try that now, thanks :)
David Bradley Jan 21st, 2008 at 18:48
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
Luke Hoersten Jan 21st, 2008 at 19:42
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.
Joost de Valk Jan 21st, 2008 at 21:46
@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.
Henri van den Hoof Jan 22nd, 2008 at 00:18
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.
Scooter Jan 22nd, 2008 at 02:06
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.
Rocky Jan 22nd, 2008 at 13:48
Good post. Speeding up improves user experience, which is important.
Hendrik Jan 22nd, 2008 at 14:37
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.
Joost de Valk Jan 22nd, 2008 at 14:42
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 ;)
Joost de Valk Jan 22nd, 2008 at 14:43
@Scooter: the question is: do you care about the popular posts being completely correct all the time?
Hendrik Jan 22nd, 2008 at 16:05
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.
Allan Stewart Jan 22nd, 2008 at 16:05
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
Joost de Valk Jan 22nd, 2008 at 16:10
@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.
Kyle Jan 23rd, 2008 at 04:19
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.
Matthias Jan 23rd, 2008 at 09:51
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..
Ruud Kok Jan 23rd, 2008 at 22:03
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/
Joost de Valk Jan 23rd, 2008 at 22:15
@Kyle & Ruud: read it too, read Matt's blog daily, of course ;)
New Orleans SEO Jan 24th, 2008 at 08:34
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.
Allen Jan 24th, 2008 at 16:04
These are some great tips. I'll have to look into implementing some of them, especially when I start generating more traffic.
Stuffel Jan 25th, 2008 at 03:03
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.
mediamind Jan 25th, 2008 at 18:16
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.
Shack Dougall Jan 26th, 2008 at 08:08
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?
Patrick Daly Jan 29th, 2008 at 15:12
The reduction of queries makes total sense - thanks for even more tips!
Lars Bachmann Jan 29th, 2008 at 21:48
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.
Mario Feb 6th, 2008 at 22:51
Thanks much to do...great feed
DazzlinDonna Feb 10th, 2008 at 17:56
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.
Joern Feb 18th, 2008 at 20:27
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
Marketing Articles Apr 14th, 2008 at 10:02
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
Jacob Stoops May 7th, 2008 at 21:40
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.
Marios Alexandrou Jun 11th, 2008 at 01:36
Where's the plugin that will transform every post into quality linkbait and submit to all of the top tier social networks? :-)
cesar Jun 13th, 2008 at 03:35
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
Sudar Jul 1st, 2008 at 13:18
I guess there is some problem with your code tag. Some of the code in the article are not displaying properly.
Joost de Valk Jul 1st, 2008 at 15:32
Thx for noticing Sudar, fixed.
JP Jul 24th, 2008 at 17:41
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!
JP Jul 24th, 2008 at 18:15
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
Richard Jul 31st, 2008 at 17:31
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.
Make it faster | www.redips.net Aug 27th, 2008 at 07:45
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 :)
Beijing Aug 31st, 2008 at 17:28
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.
Phoenix Window Cleaner Guy Sep 3rd, 2008 at 10:00
@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.
Holger Sep 24th, 2008 at 16:39
a tip from http://www.dailyblogtips.com/remove-the-hyperlink-from-single-post-titles/
some more tuning tips inside the blog - great informations
sunilkumar Sep 26th, 2008 at 19:58
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..
HandandPaw Oct 13th, 2008 at 02:28
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
Tony Thompson Oct 14th, 2008 at 17:00
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
Raj Oct 15th, 2008 at 06:19
Nice tips. I am using Wp_Cache since a long time and it works!
Royce Tivel Nov 16th, 2008 at 19:13
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.
videoonlinego Nov 18th, 2008 at 00:46
It is not out-of-date information? Because I have other data on this theme. http://video-online-go.ru/map.html