Plugins versus the functions file

Sometimes I take on the maintenance of existing WordPress-based websites, and obviously part of my initial work is to assess a site’s performance, stability, extent of customisation, etc. It all boils down to getting to know what I’ve taken on so that I can find the easiest ways to maintain it in the future.

One thing I often find is that a site has a very large number of plugins (20 or more), but that quite a few of them are very small and have no admin interface – that is, you just install them and they do their job. That’s fine – if only all plugins were as focussed and easy to use!

But – every plugin you add to a WordPress site will cause the site to slow down. Only a tiny bit in most cases, but the performance hit is there. For each plugin, WordPress has to find and read at least one extra file, and check the site database for settings.

Let’s think about how you can avoid a certain proportion of this performance hit.

The Functions File

Every WordPress theme has a file called functions.php, and the contents of this file are run each time a WordPress page is loaded. If you have some simple plugins installed (for instance, a plugin that removes certain items from the page header, or changes a post’s content in some way when the post is displayed), why not just put their code into your functions file and remove the plugin? The more plugins you can migrate to the functions file, the faster your site will be. Granted, we’re probably talking no more than 1 or 2%, but every little helps.

Two of my own plugins can easily be placed into the functions file in this way – ZigPress Clean Head and ZigPress Hide Update. Just take the entire contents of each plugin file and paste it at the end of functions.php.

A PHP Widget

Some plugins offer a slightly customised version of one of the standard WordPress widgets, or they offer new widget functionality which is nevertheless very simple. Maybe you code simple plugins yourself, and you find yourself writing lots of similar widgets that do quite simple things. If you’re into PHP a bit, one way of ditching still more plugins is to install the PHP Code Widget. This little beauty works just like the text widget, except that you can insert PHP code as well. And with careful use of the PHP global command, you can access almost any WordPress data. Ideal for widgets containing customised lists of tags, categories or posts.

A Word of Warning

With the first method, you are effectively killing all forms of update warning or process for each plugin that you put in the functions file. So think about whether this might affect your site if you upgrade to a new WordPress version. If your plugin doesn’t access the site database, it’s less likely to be a problem, but you never know.

This is less likely to be a problem with the second method, because in that case you’re probably familiar enough with PHP to figure things out if something goes wrong.

Reducing the number of plugins is of course just one way to get a WordPress site to run faster – others include reducing the number of HTTP requests, caching, and minimising the number of files that are called from remote domains. I’ll talk about those sometime soon.

11 Comments

  1. I never thought that adding a plugin will slow down my site, but now I`m starting to revise my plugin list.

  2. Very useful information. I have a lot of plugins that I don’t even use, and in some cases multiple plugins doing the same job. I will be doing some serious house cleaning because of this post.

  3. The PHP code widget sounds like a winner. I’m in the process of overhauling all my plugins ( only about 10… ) after discovering that the way my social booking plugin ( since replaced ) worked was killing my blog. 5 irrelevant keywords dominating my blog, 6000+ occurrences over a 250 page blog, and also causing some duplicate content issues indexing issues it seemed.

    I’ll definitely be looking deeper into plugin options in future.

  4. I am very new to WordPress and I would be lost without all the great plugins. I have learned that it is better to keep your list down to as few as you need. I wish someone would write a plugin that simplifies the css style sheet modification – such as colors and layouts – I have been able to do it, but it takes quite a bit of revision. Thanks for your great information.

  5. I never knew that the plugins slow down my site to such an extent. It was obvious that they slow the site down, but I did not imagine the amount really. Now I will definately start revising my site and looking for plugins doing the same job. Hopefully it’ll help to make the site faster. Are there any tip of what to do if reducing plugins doesn’t suffice?

  6. This is really good, when I design templates they are usually not with a lot of custom PHP, so this is a great thing to start doing. This is my first comment here and I love your themes by the way. Keep it up.

  7. I am curious what your thoughts are now that WordPress released 3.0 which eliminates some plugins that we used to have installed. Also, what effect would a major upgrade like 3.0 have on the functions files if you customized them?

  8. Hey thanks for the information. I had never considered the performance hit a plugin would cause. I had always thought them to be nominal in terms of performance, but I guess it makes good sence that a bunch of little ones can add up quick. Thanks again!

  9. Excellent point on the plugins slowing things down — you’ve just added more to my to do list testing what hits my performance and how badly ;). Currently my WordPress site isn’t a huge traffic monster anyways, but maybe I’ll find some time to optimize a bit anyways. Loadstorm is a good free service I’ve used to do performance testing with/without plugins — I’ve still got an account there that I’ll use again for this.

  10. obvious that they slow the site down, but I did not imagine the amount really. Now I will definately start revising my site and looking for plugins doing the same job. Hopefully it’ll help to make the site faster. Are there any tip of what to do if reducing plugins doesn’t suffice?

  11. with google caffeine it is even more important to optimize your site for speed. good article definitely smart to avoid plugins if possible.