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 thefunctions.php
page.You can add
include 'custom-functions.php';
code to your functions.php file in order to includecustom-functions.php
.Remember the
custom-functions.php
must be in theme folder or define the path to it.Hope this worked for you.
You can also use funtionality plugin
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.