Today WordPress is the most liked CMS blog system. It has huge extensibility and ease to manage. Even a user who does not have programming skills, can easily manage WordPress hosted website. Using different plugins, we can enhance WordPress site functionality. Add new features using plugin management module.
In this post we will showing you How to create custom WordPress plugin from scratch. WordPress plugin provide hook functions, which can be integrated with it and work like part of it. Lets start it…
Steps to Create Custom WordPress Plugin from Start
WordPress Plugin files store under wp-content/plugins/ directory. So if your first custom plugin name is sample-plugin then create a PHP file using same name like sample-plugin.php. Must choose unique plugin name.
Now place below code inside sample-plugin.php file. These are the basic plugin parameters.
* Plugin Name: Sample Plugin
* Plugin URI: http://www.example.com/
* Description: creating custom plugin for example.
* Version: 1.0
* Author: Harish
* Author URI: https://codefixup.com/
Upload this file on WordPress directory. File structure should be like wp-content/plugins/sample-plugin/sample-plugin.php
After doing this check in WordPress admin dashboard under Plugins -> Installed Plugins. You will found installed sample-plugin named plugin. Now activate this plugin to integrate with WordPress site.
Add Plugin Option in WordPress Side Menu:
To show this new created sample plugin in WordPress side bar add below code in sample-plugin.php file.
add_menu_page( 'Sample Plugin Menu Page', 'Sample Plugin Menu', 'manage_options', 'sample-plugin-menu', 'start_init' );
Now Sample Plugin Menu option is showing in WordPress side bar. Check above screenshot.
Create Custom Function in Plugin to Add New Feature:
As you check in above add_action code. we have added “start_init” parameter as a function. You can define any custom code inside this function. See below example code.
echo "Your First Custom Plugin is Ready to Use";
So now your plugin is ready to use. By following these steps you can create own custom WordPress Plugin.