It is a misconception that WordPress is merely a blogging platform, when in reality it is also a powerful CMS tool with a huge capacity for innovation. One of the commonly used programming functions on WordPress is writing a plugin. This is how it can be done.
Step 1
The first step while writing a plugin on WordPress, is to assign a unique name to your plugin. For example,’ Hello-World’. After this is done, a new folder has to be created and named ‘hello-world.’ Within the folder, create two documents- readme.txt and hello-world.php. The content within these files will be added later.
Step 2
Now at the very basis of a plugin are two programming functions known as add_action ($tag, $func) documentation and add_filter ($tag, $func) documentation. The difference between the two lies in the fact that the add_action performs a specific action at various points of an execution of WordPress, while add_filter performs filtering of the data (e.g. escaping quotes before mysql insert, or when output is done to the browser).
Step 3
Once this is done, open the hello-world.php file and add the following information:
<?php
/*
Plugin Name: Hello-World
Plugin URI:
Description: A simple hello world wordpress plugin
Version: 1.0
Author: Balakrishnan
Author URI:
License: GPL
*/
?>
Now save the php file.
Step 4
Now place the hello-world folder to the plugins folder in wp-content sub-folder of the WordPress directory. Now, go to the WordPress admin panel and enter the plugins panel. There you will see the hello-world plugin ready to be activated. An example is here, in the screenshot.
Step 5
The finals step is to actually make the plugin worthwhile and make it to do something. For example, we can make the hello-world plugin write the words hello-world, whenever we call upon it. To do this, we place the add_action code below the entered plugin information in the recently created hello-world.php file.
<?php
/*
Plugin Name: Hello-World
Plugin URI:
Description: A simple hello world wordpress plugin
Version: 1.0
Author: the_author_name
Author URI:
License: GPL
*/
/* This calls hello_world() function when wordpress initializes.*/
/* Note that the hello_world doesnt have brackets.
add_action(‘init’,’hello_world’);
function hello_world()
{
echo “Hello World”;
}
?>