Whenever you’re adding a new feature to your WordPress site or creating a new theme, one of the very important things to do is to decide whether the feature is a theme-specific or theme independent.
For example, if you’d like to create a new Custom Post Type called Portfolio, then the code to create the CPT shouldn’t belong to your theme. This is very important to make sure users won’t lost their Portfolio posts when they change their theme in the future. The best way to handle this it to create a site functionality plugin.
In this tutorial, I’ll show you to create your own site functionality plugin using a plugin called Pluginception.
Adding a new plugin (or feature) to your site is really easy. First, click on the Create a New plugin link.
Then, give your plugin a name. The rest of the field are just optional. Once you’re done, hit the “Create a blank plugin and activate it” button at the bottom of the page.
Next, simply put any code into the newly created plugin. Make sure you’re using the right PHP code.
One of the awesome things about this plugin is whenever there’s an error in your code, the plugin will simply be deactivated. This is to make sure the code won’t break your site. That’s pretty cool as you can safely add a new code to a live site (although its not recommended)
If you’re adding lots of new features to your site, instead creating a new plugin for every feature, you could just create a plugin and put all the additional codes into this plugin. Make sure you give the plugin a meaningful name such as “Site Features” to prevent you accidentally delete or disable the plugin.