WordPress: Create a Plugin
Customize and modify a WordPress site using your own custom plugin. Creating a plugin can allow you to change aspects of the core WordPress, a theme, or one of its plugins while keeping your changes upgrade safe and theme independent.
To get started you must create a plugin folder for your file to reside in. Name your folder something identifiable, were going to use ‘example-plugin’ for this walk-through. Place this in your WordPress installations wp-content/plugins folder.
Within your new folder create a PHP file inside that folder that matches your plugin name, ours is called ‘example-plugin.php’. Add the following to the file contents:
* Plugin Name: Example Plugin
* Plugin URI: http://nathaneyre.com
* Description: Description of plugin
* Version: 0.0.1
* Author: Nathan Eyre
* Author URI: http://nathaneyre.com
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*Do something here*/
The header is made up of meta information about your plugin:
- Plugin Name: The plugin name as it is to be displayed on the WordPress plugin page.
- Plugin URI: The web address of the plugin (optional).
- Description: A short description about the plugin.
- Version: The current version of the plugin.
- Author: The plugin authors name.
- Author URI: The plugin authors web address.
Once the plugin is activated from your WordPress dashboard any code within it is run. You can now add any additional code to this file just as you might a themes function.php file.
This is the bare minimum to get a plugin operational. You can also add a readme.txt file to let WordPress know more about your plugin and add additional files and folders with assets.
When creating a new plugin I use a template which I can quickly modify to get up and running even faster. This base template is available to download here.
For more information check out Writing a Plugin on the WordPress codex.