There are a lot of factors that influence performance on your WordPress site, and one of the tricks that "experts" will often tell you to do is avoid plugins. They will tell you it is better to place functionality inside of your theme, instead of activating a plugin. Is this true?
When it comes to the performance of your WordPress site, there are a lot of factors that influence the overall results. These factors include how well your theme is written, the number of images and other resources that must be loaded, how well your site is cached, the quality of your activated plugins, and many more. Two factors, however, that have zero impact on the performance level of your site is the number of plugins (yes, I'm 100% serious) and whether pieces of functionality exist as a plugin or part of your theme.
If you do a quick Google search for "how to add a contact form to WordPress", you will probably notice a heavy trend when it comes to tutorial titles. Most of the tutorials will include something along the lines of "... without a plugin". This trend, which exists for dozens of tutorial topics, brings into mind the idea that plugins must be bad and possibly that they hurt your site's performance. Having the words "without a plugin" so common in tutorial titles, as well as forum posts, many people have come to believe that it is better, particularly for performance, to include pieces of functionality inside of themes (whether your own or one you have purchased) rather than rely on a plugin to provide it.
The first response I have to this commonly held belief is that it is completely unfounded, and actually, entirely incorrect. There are several aspects to the reason this belief is wrong, and I will go through them point by point. I will also briefly touch on the belief that fewer plugins are better, which is (usually) entirely incorrect as well.
1. Functionality Is Better Placed in a Theme Than a Plugin
The idea behind this belief is that plugins are often the source of problems on your site, either because they are poorly written or they conflict with something in your theme. If plugins are often bad, then it makes sense that it is better to place functionality (such as contact forms) inside of the theme, right?
Wrong, and here is why:
"Whether code is loaded at point Y or point X, it is no more efficient."
First, the only difference between code that is placed in a theme and code that is placed in a plugin is the time of execution. Active plugins are loaded and executed before the currently active theme, but other than that, there is zero difference in the way that code contained within each is executed, and also zero difference in terms of how efficient the code is. If you’d like a great diagram of the WordPress core load process, see this Stack Exchange post.
Whether code is loaded at point Y or point X, it is no more efficient.
Second, with point number 1, we now have to ask "how is a theme the better place for functionality?", since both plugin code and theme code gets executed in the same way. The answer is simple. While themes have zero benefit over plugins when considering where to place pieces of functionality, it turns out that plugins have a couple of significant advantages over themes. I will walk through these advantages in a moment.
2. Code in Themes Performs Better Than in Plugins
I really don't know where this comes from, though I suspect it is has to do with the fact that people are often scared of plugins, and they frequently hear that plugins cause performance issues on a site. The fact of the matter is that this belief is ludicrous at best. As stated above, there is zero difference (except for timing) in the way that plugin code is executed, when compared to theme code.
If you place a function into a plugin, execute it, record the timing, and then do the same thing with the function but while it is placed in the theme, you will find that there is zero difference. They both execute with the same speed and neither has any direct advantage over the other, in terms of performance.
This brings up the question then, are themes ultimately better than plugins for pieces of functionality? The short answer, no, absolutely not.
Some Reasons Plugins Are Better
We should now ask, are plugins ultimately better for pieces of functionality than themes? The short answer, yes, most of the time they definitely are. But why? Well, there are a few reasons.
- Separating your code into "chunks" is one of the best things you can do for large projects, as it makes the entire project much easier to maintain, and debug in the case of a problem. By placing your separate pieces of functionality into their own dedicated plugins, you effectively create these "chunks". Each plugin is maintained separately, which (as you will find) can make it infinitely easier to track down problems.
- If something breaks, you simply deactivate the plugin. Let's say that the contact form on your site is integrated into your theme and it breaks, bringing the site down with it. What do you do? If you don't have the skills or know how to replace the contact form with a functioning one, you are in big trouble. On the other hand, if the functionality is provided by a plugin, you simply deactivate the plugin, and bring it back online once the problem is fixed, or you go find a new one.
- If you ever want to change themes, as most sites will do at least once or twice, you will lose every bit of custom functionality you have (including short codes) because the new theme will either not have the same functions, or it will execute / build them differently. If you, however, had all of your short codes inside of a plugin, as well as things like contact forms, all you have to do is upload the new theme and activate it: everything will still work just as before. Isn't that right there a good enough reason to say that plugins are better for separate pieces of functionality than themes? I believe it is.
- Plugins can each be separately updated and enhanced. If you add improvements to a theme, then the entire theme has to be updated. How many times have you seen a user of a theme add customizations to the style.css or functions.php? If they have done so, it is impossible for them to update the theme and get the new improvements without manually moving all of their changes over. This is assuming they have not created a child theme, which they should have but many users don’t. When the improvements are placed into a plugin, the user has to do nothing more than update the plugin from their Dashboard.
It goes further than just these four reasons, but it should already be clear the huge advantage plugins have over themes for separate pieces of functionality.
This now brings me to the question of whether it is a bad thing to have a lot of different plugins. You can probably imagine how quickly the number of active plugins will expand if you are placing each major piece of functionality into separate plugins. Does this cause a problem? What about once you reach 10 plugins? Isn’t that a lot? How about 20 or 30? Isn’t that extreme?
During WordCamp Kansas City 2012, I had the opportunity to spend some time talking with Otto, who is one of the top developers for WordPress and also one of Matt Mullenweg’s right hand men. Otto does most of the development on Matt’s personal site and he told me that there are dozens of small functionality plugins running on that site. Each of the plugins has specific tasks and they all run perfectly side by side, even though there are a lot of them.
I personally run about 50 plugins on my Pippin's Plugins site.
The point is that plugins do not cause performance issues simply because they are plugins, not even with 100 or even 200 active at the same time. Performance problems with plugins come from those that are poorly written, not the number of plugins. You could easily cause more performance problems with a single poorly written plugin than with 300 simple, well written plugins.
Performance issues usually come down to loading resources and performing database queries, so plugins that do a lot of these tend to impact performance. Plugins that do not perform queries on the database or load resources have zero (or very near zero) impact on performance, and that is why you can literally run 300 plugins on your site with no impact.
I also know that WP Candy runs upwards of 80 or 90 active plugins at all times.
The key to remember is that the number of plugins has zero impact on performance, only the quality and type of plugin impact performance.
The second key point to remember is that code in plugins runs exactly the same as code in themes, so get rid of the idea that it’s better to place functionality in your theme than a plugin. Themes are supposed to control the visual aspects of your site, not the functionality.
The last point to remember is that plugins are only evil when built poorly. Plugins themselves are never inherently bad; they are only bad because the code that makes up the plugin is bad.
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post