Make Plugins in Wordpress

Advertisemen
Wordpress is a Powerful Content management system with many attractive features.Almost anything can be scripted with wordpress. You can extend wordpress either by means of plugin or by a theme.
So now i am telling you how can you write wordpress custom plugins and started with Hello World Plugin.

Note: Before making wordpress plugins just remember below terms

  1. Always you chose a unique name to your plugin so that it doesnt collide with names used in other plugins. 
  2. Make sure you comment wherever and whenever necessary in the code.
  3. You will to test the plugin in your localhost (using xampp) along with latest version of wordpress.
Step 1: Plugin Files & Names

Assigning unique names, documenting and organizing the plugin files is very important part of plugin creation.
Make Plugins in Wordpress,plugins in wordpress,wordpress plugins make plugins

Although wordpress allows you to place the plugin php file directly into the wp-content/plugins folder, for a good plugin developer you will need to create a folder named hello-world and within place readme.txt(see the read me description) and hello-world.php.

Step 2: Plugins Basic
Now before getting ahead first of all know all basic to develop plugins.The heart of a wordpress plugins is the below 2 functions (commonly called `hooks`)
  1. add_action ($tag, $func) documentation
  2. add_filter ($tag,$func) documentation

It is very important to know the difference between the above functions.
  • add_action –> does an action at various points of wordpress execution
  • add_filter –> does filtering the data (eg. escaping quotes before mysql insert, or during output to browser.

Step 3: Plugin Information

  • Open your hello-world.php and in the first line, add this commented plugin information to your file.

<?php
/*
Plugin Name: Hello-World
Plugin URI: http://techdilute.blogspot.com/
Description: A simple hello world wordpress plugin
Version: 1.0
Author: Balakrishnan
Author URI:http://techdilute.blogspot.com/
License: GPL
*/
?>
  • Save this php file,
  • Place the plugin folder to wordpress > wp-content > plugins,
  • Go to your wordpress admin > plugins and you will see the new plugin listed, waiting to get activated.
Step 4: Full Coding for Hello World Plugin

<?php
/*
Plugin Name: Hello-World
Plugin URI:http://techdilute.blogspot.com/
Description: A simple hello world wordpress plugin
Version: 1.0
Author: Balakrishnan
Author URI: http://techdilute.blogspot.com/
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";
}
?>
  • Thats it! 
Our Hello World plugin is nearly done and with just few lines of code. When our plugin is activated, add_action command calls our hello_world() function when wordpress starts loading.
Advertisemen