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.



by Gyutae Park on 21 January, 2008 at 18:18
These are great tips Joost. Especially important for preparing for any traffic spikes as well.
by Adam Dempsey on 21 January, 2008 at 18:21
Some great tips! never thought of hard coding the header values, going to try that now, thanks :)
by David Bradley on 21 January, 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
by Luke Hoersten on 21 January, 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.
by Joost de Valk on 21 January, 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.
Pingback: Ryd op og gør din WordPress-blog hurtigere
by Henri van den Hoof on 22 January, 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.
Pingback: Make your WordPress Digg proof!
by Scooter on 22 January, 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.
Pingback: Matt Herzberger.com » Blog Archive » Here is your del.icio.us goodness for 01-22
by Rocky on 22 January, 2008 at 13:48
Good post. Speeding up improves user experience, which is important.
by Hendrik on 22 January, 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.
by Joost de Valk on 22 January, 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 ;)
by Joost de Valk on 22 January, 2008 at 14:43
@Scooter: the question is: do you care about the popular posts being completely correct all the time?
by Hendrik on 22 January, 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.
by Allan Stewart on 22 January, 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
by Joost de Valk on 22 January, 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.
Pingback: » Fragen & Antworten bei Elch-Salami und chinesischem Bier | seoFM - der erste deutsche PodCast für SEOs und Online-Marketer
by Kyle on 23 January, 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.
by Matthias on 23 January, 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..
by Ruud Kok on 23 January, 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/
by Joost de Valk on 23 January, 2008 at 22:15
@Kyle & Ruud: read it too, read Matt's blog daily, of course ;)
Pingback: Wordpress beschleunigen » - Javascript Blog
by New Orleans SEO on 24 January, 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.
by Allen on 24 January, 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.
by Stuffel on 25 January, 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.
by mediamind on 25 January, 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.
Pingback: Linkage for January 25 | Learn Technology Online
by Shack Dougall on 26 January, 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?
Pingback: 13 Great Articles - January 26, 2008 | My lucky number 13
by Patrick Daly on 29 January, 2008 at 15:12
The reduction of queries makes total sense - thanks for even more tips!
Pingback: Speed Up Your Slow Loading Blog Theme | Social Marketing Strategies from Social Marketing Expert Peter Lenkefi
by Lars Bachmann on 29 January, 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.
Pingback: FÃ¥ en hurtigere Wordpress
Pingback: Friday Tea Time - 2/1/08
Pingback: This Month In SEO - 1/08 - TheVanBlog
Pingback: links for 2008-02-04
Pingback: UriShare - Make your wordpress digg proof!
by Mario on 6 February, 2008 at 22:51
Thanks much to do...great feed
by DazzlinDonna on 10 February, 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.
by Joern on 18 February, 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
Pingback: 5 Easy Wordpress Tweaks For SEO and VEO | Social Marketing Strategies from Social Marketing Expert Peter Lenkefi
Pingback: Make WordPress Faster With Some Simple Coding Tweaks - TheVanBlog
Pingback: Kaip paspartinti wordpress
by Marketing Articles on 14 April, 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
Pingback: Speed Up WordPress Blog
by Jacob Stoops on 7 May, 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.
Pingback: DevWebPro » Post Topic » Make WordPress Faster
by Marios Alexandrou on 11 June, 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? :-)
by cesar on 13 June, 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
Pingback: Keeping your Blog Alive When You’re Tired of Writing | Make Money Online Blog
by Sudar on 1 July, 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.
by Joost de Valk on 1 July, 2008 at 15:32
Thx for noticing Sudar, fixed.
Pingback: Speed Up Your WordPress | Politeknik UI Community
Pingback: WordPress SEO | Politeknik UI Community
by JP on 24 July, 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!
by JP on 24 July, 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
by Richard on 31 July, 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.
Pingback: Lazy Guide to Wordpress SEO | Wordprezzie
by Make it faster | www.redips.net on 27 August, 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 :)
by Beijing on 31 August, 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.
by Phoenix Window Cleaner Guy on 3 September, 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.
by Holger on 24 September, 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
by HandandPaw on 13 October, 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
by Tony Thompson on 14 October, 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
by Raj on 15 October, 2008 at 06:19
Nice tips. I am using Wp_Cache since a long time and it works!
Pingback: Wordpress SEO (Search engine optimization) (Arama motoru optimizasyonu) - æ-yazi - IslandTemplates
by Royce Tivel on 16 November, 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.
by Litso on 21 November, 2008 at 16:33
Spam ^
Anyway, I needed to leave a reply somewhere to see your relish plugin at work. Ignore this message.
Pingback: High load web hosting. Tips optimasi script joomla, wordpress dan lainnya. — Tadulako Hosting Indonesia - Blog
Pingback: How To Speed Up A Sluggish Wordpress Site | WP-Blogger
by raj 3gpindia on 27 March, 2009 at 08:54
Very nice information.i am looking for this for long time.i bookmarked your blog ,Thanks for this.
by MiguelAlvarez on 4 April, 2009 at 04:58
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.
by Shack Dougall on 4 April, 2009 at 05:57
@MiguelAvarez - The Revision Control Plugin can really help if you want to limit or disable the number of revisions.
by Josh on 7 April, 2009 at 04:37
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
Pingback: How to speed up your wordpress installation and blog/website page loading time? « Digitizor
by FoeL on 20 April, 2009 at 02:52
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
by Matt@ThisBarSucks on 29 April, 2009 at 12:20
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 :-)
by Youri on 6 May, 2009 at 22:01
I prefer to set the meta tags static (maby a little bit work, but hey who cares!).
Thanks for the post!
-- Youri ( devfolio )
Pingback: SEO per Wordpress: segui questi 9 suggerimenti di Yoast « My Social Web
by helsekosten on 12 June, 2009 at 16:08
Thanks, oh my god that was so needed. A thing to clean all my dirty plugins. Sweet!
by Michael on 16 June, 2009 at 05:53
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?
by Richard on 9 July, 2009 at 16:17
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.
Pingback: 10 strike plan to grease your site for speed.
Pingback: Blogging Tips: SOB's Top 7 Tweaks To A Faster Wordpress Blog
by seo company on 28 July, 2009 at 03:50
Thanks for this.
Pingback: How To Speed Up Your WordPress Blog
by joyoge designers' bookmark on 10 August, 2009 at 00:24
very helpful informations for seed up wp, thanks a lot..
Pingback: 18 Useful Tricks To Speed Up WordPress & Boost Performance
by fushar on 23 August, 2009 at 05:56
Nice article! I've implemented your tips on header.php, hoping for some speedup :)
by Mr.Laptop on 23 August, 2009 at 15:07
Thank you very much for your good sharing.
Pingback: 18 Useful Tricks To Speed Up WordPress & Boost Performance | Minhyeong Magazine
by Dani McDaniel on 26 August, 2009 at 08:37
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
Pingback: Accélérez et nettoyez votre Wordpress » Inside da web
by sunnybear on 17 September, 2009 at 12:26
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.
Pingback: SEO per Wordpress: segui questi 9 suggerimenti di Yoast | My Social Web
Pingback: Complex Optimization Guide Part 11. Wordpress Optimization | odd creations blog
Pingback: Guide complet pour optimiser votre référencement sous Wordpress » Inside da web
by reporttheweb on 6 October, 2009 at 07:40
Excellent tipps in this case... but sunnybear whate exactly is this script ?
by s.holstens on 8 October, 2009 at 11:05
Thank you for the Tipps =)
by Andy Fitzpatrick on 20 October, 2009 at 14:34
Cheers for the tip about Web Optimser I've been looking for a solution to this all day.
by Web Penghasil Duit on 21 October, 2009 at 09:37
Thanks for the tips. I like it!
Web Penghasil Duit
Pingback: Wordpress: Performance optimieren | bertdesign.de
by arianit on 7 November, 2009 at 00:55
Excellent tips, I used it :) Thanks
by Watch Movies Online Free on 24 November, 2009 at 00:13
Excelent Tips man, thanks
by w3digg.com on 26 November, 2009 at 07:18
Excellent tips... is there any suggestion about html compression.
by Mr Weddington on 2 December, 2009 at 14:08
Brillaint tips this was really really helpful
thanks
Matt