Introduction
Plugins are software which contains a group of functions to perform the specific task. Plugins extend the functionality of the wordpress. Plugin adds the new feature to the WordPress. WordPress plugins are written in PHP language and can be included in the wordpress easily.
In this tutorial we will see how to write your own wordpress plugin. To write your own plugin you need to know how to code in HTML and PHP also JavaScript and CSS but it is not necessary.
Steps to write the wordpress Plugin:
Step 1: Create Folder
To write a new plugin for your project first you need to organize the file structure.
Create the folder for your plugin into your wp-content folder on your server, Go into your plugin folder (Example: C:xampphtdocswordpresswp-contentplugins) and make a new folder with plugin name which you want make folder name should unique. For this tutorial we will consider ‘example-plugin’ as folder name(Plugin name).
Whenever you are going to publish the plugin for other users in wordpress plugin gallery its name should be unique it should not conflict with the other plugin name.
Step 2: Sub folder and php file:
In your example-plugin folder you can create the different folders and files to arrange your PHP , HTML , JS , and CSS files.
Example:
Then in example-plugin folder create new PHP file it will be your main PHP file name it as index.php or better to name it by your plugin name as example-plugin.php . It will contain your php functions.
Step 3: Basic information of the plugin
Once you create the php file in that file in comment describe the your plugin. This description will be shown in description of the plugin on the plugins page in wordpress. Use the below template and paste it in your PHP file.
/* Plugin Name: example-plugin Plugin URI: https://wpgenius.in/ Description: example-plugin for how to create the plugin demo Version: 1.10.3 Requires at least: 5.2 Requires PHP: 7.2 Author: Tyche Ventures Author URI: https://wpgenius.in/ License: GPL v2 or later License URI: https://wpgenius.in/ Text Domain: my-plugin Domain Path: /your-domain path */