Create a Functionality Plugin Instead of Using Functions.php

Functionality Plugins remove the expiration date of your functions
If you find this tutorial too difficult to follow, you can hire me to build your functionality plugin to suit your specific needs.

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.

If you’d rather work from a template, download and install this plugin that I created, then activate it and edit it from Plugins > Editor.

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!

27 thoughts on “Create a Functionality Plugin Instead of Using Functions.php”

  1. MaAnna says:

    Dave, that’s brilliant! Definitely putting this tip in the toolbox. I feel a lot better modifying this file than a core file in a theme that someone paid for and/or gets updated by the developer.

    1. Thanks MaAnna! I’m glad you see it that way and hope you’re able to influence a few people at the same time!

  2. Renji says:

    Hi Dave,

    Does adding many functions in functions.php file slow down WordPress? I know installing many plugins is bad, but what about functions?

    1. No, not at all. The reason you don’t want too many plugins is generally because of the number of HTTP requests they create. That’s what slows you down, rather than the number themselves. So you could have 25 plugins each with 1 HTTP request and that would likely be faster than a single plugin with 50 HTTP requests.

      That said, I usually prefer functions for small little things like this because you have full control over everything and don’t need to include HTTP requests if they’re not needed – you don’t typically check plugins for their coding efficiency, which is why installing loads of them can be detrimental.

      Thanks for your question.

      1. Renji says:

        Same here, I prefer functions too. Thanks for that nice explanation. :)

  3. chelle says:

    this post is actually great.. as a new blogger i must admit that i don’t have much knowledge regarding this matter but i am very much willing to learn more… thank you so much for sharing this one! i would love to check these out!

    1. You’re quite welcome Chelle. Best to start off the right way than having to do a lot of rework! I hope you continue to learn and become a WordPress ninja in no time! Cheers.

  4. Mercer says:

    I hadn’t heard of this idea… looking back it’s brilliant (of course!). Really liked how you determine what to keep in functions.php (anything theme dependent). I’m off to build…

    1. Thanks Mercer. I’m glad you found it so useful. Hope you help to spread the word

  5. Evan Payne says:

    This is great. I’ve been thrown off before by switching themes after creating custom post types and other functions. This solves it and makes perfect sense. Consider me a convert. (and thank you.)

    1. Thanks Evan, glad to see another convert!

  6. jzigbe says:

    Hi Dave,
    There are a number of extra sidebars that I register in every theme I make. Can that be done by this plugin? Will it not clash with the normal register_sidebar in the functions.php file?
    Thanks

    1. No, you can register multiple sidebars from several different theme files and plugins. Your function name will need to be unique of course, but you can use the register-sidebar hook multiple times.

  7. Beth says:

    Hi Dave

    I arrived at this page after reading your ‘add anything to the end of posts’ page. Doing things this way make perfect sense as I’m always worried about loosing customisation when I change themes or make other changes. I’m going to experiment doing this first on an old blog in case I make a mess of it, as I’m not a coder.

    1. Absolutely. I encourage you to give it a go. Give me a shout here or on Twitter if you encounter any problems. I’d be glad to help.

  8. Brentini says:

    My question is why on earth would you not be using child themes in all cases? Any WP theme can have children and any customization, including adding functions should be in a child theme, because, like you said, if the theme is updated, then the functions.php file remains intact.

    Don’t get me wrong, this is cool. However, for this to even be all that practical means that I would not be using a child theme as my active theme which is a huge no-no.

    1. I agree in using child themes in most cases. I have a tutorial on it and highly recommend it. However, I don’t see why you still wouldn’t use this. There are certain functions that belong in functions.php, and they should then go in your child theme’s functions.php. However, there are other functions which belong in a functionality plugin and there’s no reason why you couldn’t use a functionality plugin in conjunction with a child theme, even if it does also have a functions.php file.

  9. Art says:

    This is so cool, it’s kind of creepy. Made my day because I’m always goosey about changing a theme that someone else coded… and although I use child codes, I’ve never been able to get everything working in all the child files at the same time.

    So, great post!

    I do have one question…. in the .php file, are additional functions discrete items that are fenced with their own php delimiters, or is the entire file read as a series of functions and there’s only one set of php delimiters at the beginning and end of the file?

    Thanks again!

    1. It’s up to you. I typically leave the PHP tags open for the whole file and just add functions as I need them, but it will work just as well if you open and close after every function (though a little less efficient).

  10. Noah's Dad says:

    Thanks for sharing this. I’m in the process of trying to use something like this for adding google webmaster tools, bing, yahoo, etc….

    1. Well, you should go for it! Only takes a few minutes to set it up, and then you’re away.

  11. martin says:

    Hi that`s a nice alternative^^…but i prefer to create a mu-plugins folder inside of my wp-content folder…there you can create as many files as you want…so if you have a lot of hooks you can saperate them by special files

    cheers

    1. Well, that’s an option too, yes. Not sure that it has any advantages over this way or not; so perhaps it’s just a different way.

  12. John says:

    I am definitely going to start doing this more often. I like the idea of creating it as a must-use plugin (as Martin mentioned above)
    The beauty of the mu plugin is that it doesn’t need activating…and also clients cannot deactivate it and screw-up the site!

  13. Torsten says:

    Instead of “just” your functionality-plugin you can use one of these plugins
    http://wordpress.org/plugins/toolbox/
    http://wordpress.org/plugins/code-snippets/
    to add some extra features for your snippets organization (like loading just in frontend, backend or both).

  14. oWEB says:

    Hello,
    great idea!
    Is it possible to manage each function in the backend with button radio “yes” or “no”?

    1. You’d have to create an options page, but sure, anything’s possible.

Leave a Reply