Over the years I have found lots of different solutions and additions to a WordPress website’s functionality using functions.php. The reality is that I think there has to be a clear definition of when to put code in the functions.php file of a WordPress theme and when to simply create a plugin.
So on that note, here are some interesting posts I have found on the subject and some of the things that I found interesting and worth noting:
Stop adding code to your WordPress theme’s functions.php file
by WP Ninjas
- If you are comfortable modifying your functions,php file you are fully capable of creating a simple plugin
- It’s extremely easy
- It can mostly be copy and pasted each time you want to make a new one
- Any code you’ve already pasted in your functions.php can most likely be used in a plugin
Why You Shouldn’t Use functions.php (And What You Should Do Instead)
At the core of WordPress lies a simple principle: design and functionality should (whenever possible) be clearly separated.
That is why we have themes and plugins; ostensibly, themes are solely responsible for design and plugins are solely responsible for functionality. One should be able to switch themes without affecting functionality, and one should be able to deactivate plugins without affecting design.
WordPress Functionality Plugins
A functionality plugin is just a plugin like any other plugin you’d find in the WordPress Plugin Repository. The main difference is that it wouldn’t be publicly distributed, because it’s specific to your site. It’s one custom plugin that encompasses all your site’s custom functionality.
If you’re like me and like to keep things neat and tidy, this is a great time to use a modular approach to the code you place in your plugin.
One approach to keep things simple is to organize your functionality into similar groups and give each of them their own file. Then, include those files into the main file of the plugin using PHP includes. Make sure you notate your functions so when you return to them at a later date you know what’s going on.