Basically making a WordPress plugin is very easy. If you know the basic, you can make it super complicated, depending on what you want to achieve.
First Step: Make the directory and plugin file
To make a plugin, simply create a directory inside wp-content->plugins folder of your WordPress installation directory. Then inside that directory, create your plugin directory, for example my-plugin. Go inside that folder and make the plugin php file, let’s say my-plugin.php file.
Second Step: Add plugin information
On the very top of your plugin php code, add basic information about your plugin. See this example below:
<?php
/*
* Plugin Name: My Plugin
* Description: Description about my new plugin will be here.
* Version: 1.0.0
* Author: Habibie
* Author URI: https://webappdev.my.id/
* License: GPL2
* Requires at least: 2.9
* Requires PHP: 5.2
* Text Domain: my-plugin
* Domain Path: /languages
*/
If you are planning to seriously develop a plugin, make sure your plugin slug (in this case “my-plugin”) is unique, so there must be no other plugin using same slug as yours.
In above example, make sure you replace “my-plugin” on each cases to your own slug. Obviously the plugin name too, description, etc.
Third Step: Code your plugin
Let’s just assume we are going to make a plugin to show an HTML text on our footer area of our WordPress website.
In this step, you need to do 2 things. First, make a PHP function to be called when WordPress is showing it’s footer on your website.
Let’s say we make this simple function:
//Showing Hello World text on WordPress footer
function helloworld_on_footer() {
?>
<div>
<p>Hello World!</p>
</div>
<?php
}
Then the second thing, is to attach this function (to hook this function) to a WordPress action that you wish to use, in our case “wp_footer”, because we need to run that function on WordPress footer area. To do so, we need to do this:
add_action('wp_footer', 'helloworld_on_footer');
The second parameter on above line is the function that we made earlier.
Done!
Try to activate your plugin on your WordPress dashboard, and reload your website. You should be able to see your Hello World! text on footer area of your WordPress website.