Doing ‘X’ Without a Plugin

Inspired by a tutorial I saw this weekend, I have to rant. The tutorial was a variant on “How to Do ‘X’ Without a Plugin”, a type of tutorial the WordPress community sees a number of. That type of title, though, is infuriating to WordPress developers like myself, and actually following those tutorials in most cases is bad practice.

I think there are a couple reasons these tutorials are commonplace. One is that bad plugins exist. There’s no question that not every plugin follows best practices for coding and that some plugins cause conflicts with other plugins. The second reason is an extension of the first — that the more plugins you’re running, the slower your website will be, and by bundling the normally-plugin-territory behavior into the theme that they’ll get the desired functionality and positively impact their site’s speed. Both of those reasons are misguided, at best.

Protect Yourself From Bad Code

Yes, bad code exists. Not all WordPress developers are created equal. But those statements are true whether we’re talking about plugin authors or theme authors. If you have enough confidence and understanding to try to add some additional functionality to your website by following a website tutorial, then you should be smart enough to do yourself a favor and add it to a plugin instead. That way if something goes wrong, or you notice odd behavior on your site, troubleshooting becomes much easier when you can turn on and off bits of functionality from the WordPress admin screens.

Theme Code is not Portable

Most tutorials advocate readers place the tutorial’s code in their theme’s functions.php file. I understand why, but the problem with that approach is that themes are subject to change, sometimes frequently. If a tutorial is teaching someone to add functionality to their theme files, then they should also be educating their readers the future consequences of those actions — that when the reader changes his theme in the future, the functionality showcased in the tutorial will be gone as well.

Themes are not Faster Than Plugins

Contrary to somewhat popular belief, code in your theme files will not execute faster than if it were in a plugin. Code is parsed at the same speed, regardless of location. I don’t know where this myth started from, but it needs to be quashed. Poor code in a theme file is just as slow as poor code in a plugin file, so if you’re integrating plugin functionality into a theme in order to gain speed, save yourself the trouble and stop.

How Many Plugins are Too Many?

There is no right answer to that question. Install as many plugins as you need to get the functionality you want. You could be running 50 plugins, and if they’re all well-written, they’re likely to be executed faster than a few poorly-written plugins. It’s not about quantity, it’s about quality.