I think I’ve made some good progress in trying to get people to convert from using their theme’s functions.php file for placing their code snippets to putting them in a unique functionality plugin.
There’s many good reasons for doing this, but high up on the list is portability (keep your snippets when you change themes, or sites) and retaining your code snippets if you ever need to upgrade your theme. If you want to read more, check out Putting things where they belong.
Well, if you want to go ahead and use a functionality plugin, but are scared about the code behind it, I’ve put a template together to make things exceptionally easy.
The template below will work, but I strongly suggest that you use the plugin template from my more recent functionality plugin tutorial, Putting things where they belong.
The code and standards in that version are much better, and the accompanying tutorial is really helpful, with great examples to give you an idea of how to use it.
Install the plugin
All you need to do is download this plugin that I’ve put together and upload it to your site by going to Plugins > Add New > Upload. Once you’ve uploaded it, activate it (it will be called Functionality Plugin for SITENAME in your plugin list).
Personalise it for your site
Obviously, the plugin needs to be unique for your site, so you’ll need to customise it now. Go to Plugins > Editor and select Functionality Plugin for SITENAME.
Once you pull up the editor, you’ll see the header information already in place. All you’ll want to do is change SITENAME to your actual site name so that it’s clear what site it is for.
Then you’ll see a simple template for putting your snippets into. The way I like to do it, so that things are well organized and easy to sort through, is to put several line spaces between titles and snippets.
Keep your snippet titles capitalised so that they stand out when scrolling through the file. Remember, that since this is a PHP file, you must keep the titles commented (in between sets of //).
Also, if you ever want to disable a snippet, don’t delete it – change the title to include (DISABLED) and then comment out the snippet by putting /* before the snippet and */ after the snippet, as shown by example in the second snippet space in the template.
Does this help? Are you now more likely to use a functionality plugin? Help to spread the word!
A more recent and much improved version of this template is available here and should be used instead of this template.