Adding custom code to a website is a common practice in the WordPress environment. We are currently running a bit of custom code on our site and this is how we have done it.
Follow these easy steps to create a custom WordPress plugin for your code:
- Create a folder on your desktop called ‘my-custom-plugin’.
- Enter that folder and create a new file called ‘my-custom-plugin.php’
- Edit the ‘my-custom-plugin.php’ and add the following code to it and save your changes:
<?php /* Plugin Name: My Custom Plugin Plugin URI: https://yoohoothemes.com Description: All Custom Code Goes Here. Version: 1.0.0 Author: YooHoo Themes Author URI: https://yoohoothemes.com Text Domain: my-custom-plugin */
- Zip your ‘my-custom-plugin’ folder and upload it to WordPress under the ‘Plugins’ > ‘Add New’ > ‘Upload’ page in the WordPress dashboard.
- All your custom PHP code may be entered after the code above going forward.
This allows you to group your code neatly according to plugin and all your code can be in one place, making it easier to support and maintain.
Tip: Reference from the WordPress Codex – https://codex.wordpress.org/File_Header