“Should I write this piece of code for implementing this new functionality by adding/editing the theme files themselves or should I write it in a plugin?”
It’s a question that I have come across more than once. However, I think there are a series of questions that I can ask myself before jumping into writing any code.
Usually, the answers to these lie in the true definition of a theme and the true definition of a plugin. But we tend to overlook it many times. We often concentrate more on getting the functionality done ignoring the fact where this code should actually be.
Drawing the line based on the feature
This isn’t to oversimplify the process because I realize there is some overlap. So there isn’t a hard line to be drawn. However, I think there needs to be a significant point at which we know when something should be a child theme or a plugin.
While building a theme with even the slightest bit of advanced functionality, how should the functionality be developed? If the feature in question has to do with design but should implement a menu option to toggle something, where does it belong?
Writing the Child Theme?
For a feature that calls for something such as a font manager in the existing theme, this certainly has to do with the design. The initial reaction is to think about adding the child theme.
The thing is, the core business need here is for a font manager. This means that there is some functionality built into this request that assumes there’s going to be a set of data that must be managed.
According to all I know so far, themes in WP don’t manage data – they just the present the data. So, to that point, I believe it should be wrapped in a plugin.
Write the plugin?
Now, I recently came across a small feature to which was likely to add four widgetized areas in a customized footer above the default footer(not actually used).
The deal here was for introducing a functionality. Something that allows this customized footer to have a set of additional widgets but that functionality is already built into the WordPress API.
So, in this particular case, I chose to create a simple child theme. The theme introduces a secondary container above the footer with four widgetized areas.
Most of the times, the design-related issues are handled by child themes, and functionality related issues are handled by plugins.
Finally, understanding the core business need and how it relates to the existing WP site is crucial. It’s not always sufficient to just understand the difference in design and functionality.