I have added this post because I got many requests. In this article i will describe the easy and simple steps to create the wordpress plugin. WordPress Plugins allow to easy modification, customization, and enhancement in a WordPress blog or website.
Add the header information in top of your Plugin’s main PHP file because WordPress recognize to getting the information for Plugin management screen so it can be activated and run its functions. Below is the plugin header format:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php /** * Plugin Name: Your Plugin Name * Plugin URI: http://Plugin_URL * Description: A brief description about your Plugin. * Version: Plugin's Version Number, e.g.: 1.0 * Author: Plugin Author Name * Author URI: http://The_URL_Of_The_Plugin_Author * License: A "Slug" license name e.g. GPL2 */ ?> |
Programming Your Plugin
write the code for your plugin functionalities after the header infomation. In this section describes about your plugin, how to accomplish several tasks your Plugin will do.
1 2 3 | <?PHP add_action( $hook, $function_to_add, $priority, $accepted_args ); ?> |
example of add_action() hooks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?PHP class MyPluginClass { public function __construct() { //add your actions to the constructor! add_action( 'save_post', array( $this, 'myplugin_save_posts' ) ); } public function myplugin_save_posts() { //do stuff here... } } ?> |
Execute all functions on a specific action hook.
1 | <?php do_action( $tag, $arg_a, $arg_b, $etc ); ?> |
Complete example for plugin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?php /* Plugin Name: Prem Tiwari Plugin URI: http://freewebmentor.com/ Description: This is just example of a plugin description. Author: Prem Tiwari Version: 1.0 Author URI: http://freewebmentor.com/ */ #tell wordpress to register the demolistposts shortcode add_shortcode("custom-posts", "demolistposts_handler"); function demolistposts_handler() { //run function that actually does the work of the plugin $demolph_output = demolistposts_function(); //send back text to replace shortcode in post return $demolph_output; } function demolistposts_function() { //process plugin $demolp_output = "Hello world!"; return $demolp_output; } ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: create custom wordpress plugin, custom wordpress plugin, how to create wordpress plugin, Plugins, wordpress, wordpress plugin, WordPress Plugins