Advertisement
General

Functionality: Plugins vs Themes

by

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?


Introduction

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.


Common Beliefs

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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?

No.

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.

Related Posts
  • Code
    Articles
    Introduction to WordPress App ThemesApp theme 400
    With the increasing growth rate of WordPress powered websites, the need for WordPress themes is rising. Multi-purpose themes are becoming highly popular among website owners. Many existing themes are built mainly to address blog functionality. But with the growth of WordPress web application development, we are in need of specialized themes for different purposes. These themes are known as app themes. In this article, we going to familiarize with the concept of app themes and their usage in real world.Read More…
  • Code
    WordPress
    The Beginner's Guide to Selecting a WordPress ThemeBeginnersguide
    When you're first starting out with your site or blog, it's easy to rush into things because of the desire to get things up and running as quickly as possible. In some cases, that works fine, in others it's not always the best idea. And in this case, it's the latter.Read More…
  • Code
    Plugins
    Choosing the Right Plugin for Your Next WordPress ProjectPlugin icon 400
    Ever needed a plugin for your WordPress-based website? Of course! After all, that's how WordPress is extended, isn't it? If you're a beginner to WordPress, or even a power user, then you're likely familiar with the WordPress plugin repository, premium plugins, and so on. The thing is, there are so many plugins available that do many of the same things, it can be difficult to determine which is best suited for your particular needs. This raises the question: What do you do to find the perfect plugin for a particular need? In this post, we're going to see how to find the best plugin for exactly that.Read More…
  • Code
    Articles
    Strategies For Choosing the Right Premium WordPress Theme for Your Next ProjectPremiumwp
    You have your credit card in hand, and you are ready to buy a beautiful, premium WordPress theme for your next website or blog. But where should you begin? Perhaps a search through Google? Maybe a famous WordPress theme site? Perhaps ThemeForest.net? In this post, I aim to arm you with a few tips that will guide you when choosing a premium theme not only purchase a beautiful theme, but one that will meet your needs.Read More…
  • Code
    Theme Development
    Making the Perfect WordPress Theme: Bad PracticesWp white 400
    We discussed how to do good in the previous part of this series: We learn how to write better code, how to comply with the standards, how to make our code readable by others and so on. In this article, we're going to see how to do bad: We'll go through some of the worst practices that one can follow when building WordPress themes.Read More…
  • Code
    Theme Development
    Integrating the Envato WordPress Toolkit to Your Theme: The PluginEnvato toolkit 400
    As WordPress authors in ThemeForest, we like to make our customers happy by providing them with occasional bug fixes and enhancements to our themes. But one key problem for us is how to notify our users when an update is available for download.Read More…