A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress Plugin Application Program Interface (API). – Writing a Plugin, WordPress Codex
Basics To Know Before Creating a WordPress Plugin
In this section, we will reveal the first few steps you need to follow when creating a WordPress plugin. In addition, we will mention all the various things you need to put into consideration as you write your plugin. Great. Let’s start with the basics.
How to Name A WordPress Plugin
Before everything else, you need to come up with a unique name for your WordPress plugin. One of the best ways to determine a favorable name is to think of what your plugin will do. So, for instance, if your plugin will help people share content via social media, you can include the phrase “social media sharing” in the name. Another thing, plugin names can be several words, so don’t mince creativity.
Your plugin name must be unique to avoid conflicts with other plugins. To ensure your name is unique, you can do a Google search on the name. Additionally, you can search the various plugin directories including the WordPress plugin repository.
To name any plugin, we have to create at least one plugin file (the main PHP file), which introduces us to our next section.
How to Create Plugin Files
A plugin can be made up of a single PHP file or multiple files depending on what it’s designed to do. The most important file is the main PHP file, which is the equivalent of index.php and index.html in WordPress themes and HTML designs respectively.
It’s recommended that WordPress developers name their main plugin file after their plugin by convention. For instance, the main plugin file for a plugin called WP Renym plugin would be wp-renym.php. If adding a separator in your name, only use hyphens ( – ) between words as opposed to underscores ( _ ).
After you lay down all the code for a plugin you then compress your main folder into a zip file (in this case it would be wp-renym.zip archive) to be uploaded and installed on a WordPress site.
Adding a File Header to the Main PHP file
When naming your plugin you should add other details such as description, version, license, author name – basically everything that will appear under and alongside your plugin in the WordPress Plugins Screen – the the plugin header. For this you must use a standard plugin information header at the top of your main PHP file. This is how a typical header looks:
Naming Our Plugin
First, we checked the WordPress plugin repository and did a Google search on our name; WP Renym was free. My initial choice was WP Rename but it was already taken.
Moving on… Open a new file in your code editor, and add the following code at the top after opening your plugin with <?php:
/* Plugin Name: WP Renym Plugin URI: http://link to your plugin homepage Description: This plugin replaces words with your own choice of words. Version: 1.0 Author: Freddy Muriuki Author URI: http://link to your website License: GPL2 etc License URI: https://link to your plugin license Copyright YEAR PLUGIN_AUTHOR_NAME (email : your email address) (Plugin Name) is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version. (Plugin Name) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with (Plugin Name). If not, see (http://link to your plugin license). */
Use Your Plugin
Upload and activate your new WP Renym plugin via the WordPress Plugins Screen. Congrats on writing your first plugin!