Create WordPress Plugin from Scratch: WordPress is the most liked and popular 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 WordPress plugin from scratch. WordPress plugin provide hook functions, which can be integrated with it and work like part of it. Lets start it…
Beginner Guide to WordPress Plugin Development
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.
1 2 3 4 5 6 7 8 9 10 11 |
<?php /* * 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.
1 2 3 4 5 6 |
add_action('admin_menu', 'sample_plugin_function_name'); function sample_plugin_function_name() { 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.
Also Read:
Create Custom Widget in WordPress Theme
Fix Google Structured Data Errors WordPress
Create Custom Function in Plugin:
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.
1 2 3 4 5 6 |
function start_init() { 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.