I have a lot of custom code in my functions.php file, what I would like to do is move all of this into a plugin for example myplugin-functions.php and then include the file into the themes functions.php file.
Can I use hooks to do this or would I have to manually include the file. The reason I want it as a plugin is so that I can easily disable it without editing theme files!
You can directly create a plugin. Just copy all your codes and put it in a new folder. Plugin will call all the functions.
The Best way to this is to copy the code into something like
custom-functions.php page and the include it in the
You can add
include 'custom-functions.php'; code to your functions.php file in order to include
custom-functions.php must be in theme folder or define the path to it.
Hope this worked for you.
There is no point to create a plugin just in order to clean up your code. a plugin should be created only if it has some functionality that can be used not only with your theme.
If you have some code that you might want to dynamically disable its execution then it is better to have a setting for it in your theme’s settings page then to have a plugin for that.
as for how you should organize your files and should you create actions, you will have to be more specific about your code and what it does.
You can also use funtionality plugin
A functionality plugin is a way to separate what you might normally
place in a theme’s functions.php file, and put it in a plugin instead.
It works the same way as a theme functions.php file, but is separate
from the theme and so not affected by theme upgrades, or tied to the
theme so you loose all of your functions if you choose to switch
This plugin automates the process of creating a functionality plugin.
Simply install and activate this plugin, and your very own
functionality plugin will be created for you. You can then edit your
functionality plugin and add snippets to it using the quick link in
the admin menu.