When you need to add or modify some WordPress functionality usually you would use either a plugin or add some code to
functions.php. The problem with the latter method is that the
functions.php file is usually located inside your theme folder, and because of that, whenever you want to install a new theme you’d need to also move the functions from one file to another.
One way to avoid this problem is to use a tiny plugin, in which we will add all those code snippets that we would normally paste into the functions file. The result is the same, except for it being independent of the active theme. That means that our custom code will now keep working even when we change themes. As for
functions.php, we can keep using it for any function that is theme-dependant.
The process is terribly simple:
The first thing we need to do is create a folder inside
/contents/plugins/. You can name that folder whatever you want, like
nameofyoursite-functionality-plugin. Inside this new folder you want to create a new php file, let’s call it
Now, open that file and add the following code on it (modifying it however you see fit):
Under this header you can add as many function as you want; you can start by cutting and pasting the ones you currently have on your
functions.php file. But remember: it’s preferable to keep theme-dependant functions in
Let’s see an example of this functionality plugin with some functions already included:
That’s all; I hope it’s been useful to you!