Code in WordPress Theme Files vs Code in Plugin - HashedIn Technologies

Code in WordPress Theme Files vs Code in Plugin

Technology - 30 Dec 2016
Harish Thyagarajan

“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, but I think there are a series of questions that I can ask myself before jumping into writing any code.

Usually, the answers to these, lies in the true definition of a theme and the true definition of a plugin, but we tend to overlook it many a times and concentrate more on getting the functionality done as soon as possible 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, but 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 customised footer above the default footer(not actually used). The deal here was for introducing a functionality that allows this customised 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 that 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 the main thing I suppose, because it’s not always sufficient to understand the difference in design and functionality.

Free tag for commerce

E-book on Digital Business Transformation