The Custom Plugin vs. The Child Theme Functions

The WP Crowd
Published: November 3, 2016

It’s a battle of the ages!  In the red corner, weighing in at exactly one file: The ultra slim, light weight, nimble as a butterfly, custom plugin!

In the blue corner, weighing in at a hefty two files and extra dependency: The glamorous, expandable, child theme!

Who will win this match for title belt of WordPress custom functionality?

Custom Functionality

If you are a WordPress developer then you know the need for custom functionality is pretty much a constant.  I do a ton of work in WooCommerce and small pieces of code often do the simple jobs I need far easier and less cumbersome then full blown plugins.

The question is, where do we put this code? There’s a million ways to skin this cat, but I believe only two that are proper.

  1. Create a child theme, add the code to the functions.php file
  2. Create a custom plugin

DING! DING! DING!

WordPress Execution

Let’s talk about how WordPress handles this code for a minute.  Typically, this custom functionality is going to be thrown into hooks.  So when WP goes to execute the code in your theme’s functions or your custom plugin it will queue up the functionality where you tell it to.

So what’s the difference in using a plugin or a theme’s functions? Well, plugins are loaded right before the theme.  So if you need that order for anything, you can rest assured the plugins are coming first.

AND HERE COMES CUSTOM PLUGIN WITH A LEFT HOOK

But what if you need a plugin to be available? You’d think you’d need to do this in the theme functions then.  No sir, just hook into plugins_loaded.

AND THE UPPER CUT

So A Custom Plugin Is Better?

You bet your ass it is.  Plugins are far more modular.  What if you want to move that functionality to a new site? Or you want to change to a new theme? Well, you have to go through the entire process of making a child theme again and moving the code over.

THE CHILD THEME IS REALLY TAKING A BEATING HERE, LADIES AND GENTLEMEN

If it’s in a custom plugin you can change themes without worry.  Or just move the plugin to the new site and activate.

Creating A Custom Plugin

All WordPress requires for a plugin to be loaded is a file in the plugins folder with a plugin name in it.  For example, if you create a file called my-custom-plugin.php and add it to the wp-content/plugins/ directory with the following code, you will see it as able to be activated in your admin plugins.

Now you can throw anything you want into that file and it will be executed with every page load.

Conclusion

EIGHT! NINE! TEN! AND CUSTOM PLUGIN TAKES THE TITLE BELT!

I personally believe, and this is my sole opinion, that using a custom plugin is ALWAYS the best choice for custom functionality and code snippets.  I can’t think of one reason using a child theme would be a better solution.  Child themes are for theming, that’s it.  You need custom page templates and so on, then yes, use a child theme.  If you need functionality that’s simply to be used by your child theme, then yes, go with a child theme.  But those use cases are strictly related to the template.

Get the latest from The WP Crowd

Leave a Reply

6 Comments on "The Custom Plugin vs. The Child Theme Functions"

avatar
Sort by:   newest | oldest
Jonathan
Guest

Well said that man. Unless you already have a child theme and the custom functionality you require is theme specific, a custom plugin is always the right answer.

Russell Aaron
Guest

There are many use cases where a plugin wins everytime., I like plugins simply for the option to debug issues. If your contact form goes down, you have to debug your entire theme. If it’s in a plugin, you de-activate the plugin until resolved or you GET A NEW PLUGIN.

Trisha
Guest

For me, it comes down to remembering what is the most appropriate tool for the job and the context. I am happy to see the trend towards child themes being bundled with custom plugins, and allowing plugin functionality to continue beyond theme changes.

Sallie Goetsch
Guest

If you’re adding functionality that you want to be theme-independent, you should use a functionality plugin. Things like creating custom post types or indeed adding page excerpt support or shortcodes in widgets are all good here. But what about CSS changes? Those are generally pretty theme-specific (except possibly if the CSS is for the CPTs you create in that plugin). Aren’t you better off with a child theme if you want to modify the parent theme’s CSS or its templates?

Roy Sivan
Admin

Sallie, Definitely! Theme CSS should be put into a child theme for sure. If you are styling a plugin’s output this can also be put into a theme CSS since when you change themes you may want a new look. If WordPress took on MVC type philosophy then ALL CSS would be in the theme, and never in ANY plugin.. plugins would be strictly, and 100% functionality + data.

CJ Andrew
Guest
Interesting post with a light-heart approach to a serious issue. Love it 🙂 I learnt this myself, that functionality of any kind is best kept in a custom plugin. Always. A while back, I crafted what I thought was a useful custom feature; and because the client was happy with it at the time, we left it in a “Child Theme”. Well, turns out that after handing the solution over to them, they decided to change themes (without my knowledge). Of course the functionality immediately stopped working. I only knew about it when I got the wrong end of the… Read more »