A few months ago, I read a post on WPCandy which discussed the idea of creating a functionality plugin. I’d never heard of this before, but I was intrigued, so I read on.
By the time I was finished with the post, I was a total convert and was dumbfounded that we’d been doing things differently for so long. Now I’m going to help spread the word by telling you all about it…
What is a functionality plugin?
Traditionally, if you wanted to create a new function for your blog to add to its functionality, the advice has been to add the code snippet to your theme’s functions.php file. Now that’s all well and good and it will work fine, but what happens when you change your site’s theme (which you can guarantee will happen at least every few years) or the theme gets updated? Since functions.php is located in your active theme folder, if you change your theme, it inherently becomes defunct.
So, how do we get around it? In short, you create a plugin which will house
all most of your functions. All plugins get loaded on every page, the same as your functions.php file, so it doesn’t matter whether the functions appear in your functions.php file or a (any) plugin.
Alright, I’m sold. How do I do it?
As with all plugins, you need to create a new folder in wp-content/plugins. I tend to call mine sitename-functionality-plugin, where sitename is the name of the site that the plugin is for. Inside that folder, you’re then going to create a file called sitename-functionality-plugin.php. Once it’s created, you can open it for editing.
At the top of the file, you need to paste plugin information in order for WordPress to properly recognise the file. Use the following as a template, changing the information as is appropriate for your own site:
Once that’s in place, you’re free to edit the remainder of the file. So you can take any functions from your functions.php file and paste them below your plugin header. So for example, your functionality plugin might start to look like this:
Should I ever use functions.php?
Actually, yes. There will be select times when using functions.php is appropriate. Think of it this way; if the function is directly related to the theme or your site layout, it probably belongs in functions.php if that function would no longer be necessary if you changed your theme. An example of this might be a function that adds image sizes that are very specific to your theme, to fit into a slider for example.
However, other functions such as setting favicons for your site or creating bit.ly short URLs are independent of the theme, and you’ll want to use regardless of the theme that you’re using, so you should be putting them in your functionality plugin.
So, have you seen the light? Have you created your functionality plugin yet? Please help spread the word and share this article!