In this blog we eill discuss how to create a simple wordpress plugin from scratch this is bery helpfull for Beginner’s to create wordpress plugin, so we will learn step by step process to create simple wordpress plugin
we eill create a simple folder with name worpress-test-plugin and inside the we eill create a PHP file with same name to achive the process of Simple WordPress Plugin Development Please follow the below steps:
Crerate a folder with name worpress-test-plugin as shown in screen below.
Create a PHP file inside it with same name as shown below
Now add the below comment information about you plugin in the above php file you have created
<?php
/*
* Plugin Name: wordpress-test-plugin
* Version: 1.0.12
* Plugin URI: https://simplifyscript.com/
* Description: A lightweight, testing pugin
* Author: Simplifyscript
* Author URI: https://simplifyscript.com/
* Requires at least: 4.0
* Tested up to: 6.5
* Requires PHP: 5.3
*
* Text Domain: https://simplifyscript.com/
* Domain Path: /languages/
*
* @package WordPress
* @author Out the Box
* @since 1.0.0
*/
Now add function.php pathe in the same file, to write the plugin function
Before we begin writing the functions for the plugin, it is highly recommended to give all files, functions, and variables a unique prefix in their name to avoid any conflicts with other plugins. In our example, we’ll be using the prefix wtp, which is short for worpress-test-plugin
Create a new folder named Includes in the plugin’s main directory. We’ll use it to store supporting files used by the main file. In this folder, create a PHP file and name it wtp-functions.php. Give it the opening <?php tag on the first line.
This new file will contain all of your plugin’s functions.
We’ll have to include wtp-functions.php in the main plugin file to allow the other plugin files to use the functions it defines. Use require_once to ensure the plugin only works if the functions file is present.
Edit worpress-test-plugin.php as shown below. Then, save it and upload the file once again, overwriting the previous version when asked.
<?php
/*
* Plugin Name: wordpress-test-plugin
* Version: 1.0.12
* Plugin URI: https://simplifyscript.com/
* Description: A lightweight, testing pugin
* Author: Simplifyscript
* Author URI: https://simplifyscript.com/
* Requires at least: 4.0
* Tested up to: 6.5
* Requires PHP: 5.3
*
* Text Domain: https://simplifyscript.com/
* Domain Path: /languages/
*
* @package WordPress
* @author Out the Box
* @since 1.0.0
*/
// Include mfp-functions.php, use require_once to stop the script if wtp-functions.php is not found
require_once plugin_dir_path(__FILE__) . 'includes/wtp-functions.php';
The WordPress function plugin_dir_path(FILE) allows you to include files from your plugin folder, providing the complete path to the directory that houses the new plugin.Now, navigate back to the mfp-functions.php file in the Includes directory. As our plugin will add a new top-level link to the navigation menu of the admin control panel, we’ll utilize a custom function named wtp_Add_My_Admin_Link(). Insert the code block below into the wtp-functions.php file.
Now compress the file and upload it as a plugin in you wordpres website