Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
You could just create your own plugin or do I miss something? codex.wordpress.org/Writing_a_Plugin –  realloc Oct 29 '13 at 11:59
add comment

4 Answers

up vote 1 down vote accepted

You can directly create a plugin. Just copy all your codes and put it in a new folder. Plugin will call all the functions.

share|improve this answer
1  
Ah ok so if I just set it up as a plugin, and activate the plugin all the functions will be called anyway - so no need to include the code into my functions.php file? –  RuFFCuT Oct 29 '13 at 11:55
    
Yes, you can do that, best thing about creating a plugin is.....it doesn't depend on your theme and if you want to use it in particular theme....you can activate/deactivate the plugin. –  Abhishek Kaushik Oct 30 '13 at 5:59
add comment

The Best way to this is to copy the code into something like custom-functions.php page and the include it in the functions.php page.

You can add include 'custom-functions.php'; code to your functions.php file in order to include custom-functions.php.

Remember the custom-functions.php must be in theme folder or define the path to it.

Hope this worked for you.

share|improve this answer
    
Thanks for answering, I have thought of doing I like this before - but ideally I would like it to be a plugin is there not a way to automatically add the "include 'custom-functions.php'" into the functions.php file? –  RuFFCuT Oct 29 '13 at 11:50
    
Oh i got that you mean that you want to create plugins so instead of describing the procedure please follow instruction here : doitwithwp.com/create-functions-plugin –  Sudeep Acharya Oct 29 '13 at 12:15
add comment

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.

share|improve this answer
add comment

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 themes.

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.