As you develop your WordPress website, you need to add additional functionality. How do you add it? You can write custom code that you add to your theme in the functions.php or create a custom site-specific plugin.
Both options allow you to add the code to WordPress. Where you choose to add the code affects how it functions.
Theme or Site-specific plugin?
Is the code you are going to add specific to how the theme or do you want it to work even when you decide to switch themes? If the enhances to your theme, you want to add your code to the functions.php. This code only works when you are using this theme. If this code needs to work no matter what theme you have installed, than you need to create a site-specific plugin.
What type of code do you add to a site-specific plugin?
- Custom post types
- Custom code snippets
Steps to create the plugin
The steps for creating a site-specific plugin are the same for any plugin.
- Create a new folder for your plugin. Use the format of yourwebsitename-plugin.
- Create a new file. Use the name of yourwebsitename-plugin.php.
<?php /* Plugin Name: Site Plugin for yourwebsite.com Description: Site specific code changes for yourwebsite.com */ /* Start Adding Functions Below this Line */ /* Stop Adding Functions Below this Line */ ?>
- Add your code to your plugin file.
- Upload code including the folder to your website.
- Activate and test.
With your site-specific plugin, you can add new features or functionality to your website by adding the code to your plugin. By adding the code to your plugin, you keep your code separate from your theme. When you need to add a new code snippet or upgrade your theme or WordPress, you won’t break your website.