The power of wordpress is behind it’s plugins. Some people think that developing a wordpress plugin is a hard work. But believe me with the simple steps i am going to tell you everyone can write a WordPress plugin. Through wordpress plugin you can add alot of functionality in your wordpress site. You can filter the content dynamically and replace it with any data, you can create wordpress widgets through plugins and many more.
Here are the simple steps to write a wordpress plugin:
Step 1. Create a new PHP page on any text editor like notepad or Dreamweaver.
Step 2. Add following code at the top of the page:-
1 2 3 4 5 6 7 8 9 | <?php /* Plugin Name: YourPluginName Plugin URI: http://www.7tech.co.in/ Description: This plugin is just for testing from http://7tech.co.in Author: Ankur sharma Version: 1.00 Author URI: http://www.ankursharma.net */ |
Replace the Plugin Name, URI, Description, Author name, Version and Author URI with yours.
Step 3. Now first we will create a admin option page. Use the code below for plugin settings page.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | add_action('admin_menu','funname'); //wordpress will call the function funname() at the time of admin menu creation function funname() { if (function_exists('add_options_page')) { //this will add a new admin menu page add_options_page('page title', 'page name that will b displayed', 8, __FILE__, 'funtobecalledonclick'); } } function funtobecalledonclick() { //here write anything you want in the plugin settings page echo 'hiiiii'; } |
Step 4. Ok, now we will create the functionality part of the plugin. Use the code below for the functionality part of the plugin.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | add_filter('the_content', 'functionname'); //this will call the function functionname() before displaying the content to users. function functionname($content) { // it will check for the string [string to be replaced in the content] in the content and replace with the return value of functiontobecalled() if (strpos($content, "[string to be replaced in the content]") !== FALSE) { $content = str_replace("[string to be replaced in the content]", functiontobecalled(), $content); } return $content; } function functiontobecalled() { //Write here whatever you want to display on the screen echo "i am called from plugin"; } |
That’s it, your own wordpress plugin is ready. Just Zip it and install it to your wordpress site
Happy Blogging…
very interesting, thanks
Gee whiz, and I tuhgoht this would be hard to find out.
Aprendi mucho