Home > Wordpress Development > My First Plugin Development

My First Plugin Development

Hello readers this my first blog on wordpress plugin development . When i started with wordpress development i was dam tensed , i din even know how to install but then when i went into deep i got to know how its dam easy . Just follow my steps you would know how to create a plugin . Soon i would add a video tutorial for this.

  • Before going anywhere please refer this document
  • In this blog will create a plugin which will display “Regards, Author” after every blog content.

Step 1:  Select a nice name for the plugin which is unique . You could try googling it or just prefix with project short code.
My file name:

ins-content-plugin.php

Step 2: Now create the folder into /wordpress/wordpress-content/plugin/your-plugin-name/ins-content-plugin.php

Step 3: Now your actual plugin development starts. For your plugin to get displayed into wordpress plugin listing you need to specify following commented lines as below.

/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/

Content listed into the plugin manager.

Step 4: Now comes the fighting with the hooks of the wordpress. Actually its dam easy just could find all the hooks into codex . There are basically two function which mainly deals

with hooks:

  • add_action() This function is used like an event used in vb.net .(For ex, if i want to call a particular function on head load.)
  • add_filter() This function is basically for manipulating with the post and all the content.

Will go into the details as needed.

As we want to play with the content so we would be requiring add_filter function.


add_filter('the_content','append');

Now you might be wondering what are the parameters into this function. The first parameter is the hook
as when to call the function rather an event. So the ‘the_content’ is a event called on every content load.
ie. Page,post,link. The second parameter is the function name to call .
Step 5: Now time to declare the actual logic.

function append()
{</pre>
<pre style="padding-left: 30px;">$append_value = "<br/>Regards,<br/>Author";
echo $content.$append_value;
}

Step 6: Activate the plugin from the plugin manager. Then open your wordpress and you could see

Regards,
Author

Appended on every post . But You could face a problem that this custom content would be placed on the page too.

That we don’t want . So we would use is_page() function to check if the content is in page or its a post. So the above code would change to

function append()
{
   if( ! is_page() )
   {
       $append_value = "<br/>Regards,<br/>Author";
       echo $content.$append_value;
   }
}

Oh cool Thats the end . Dam simple just by the time i will post few of the developments with the wordpress
Please let me know how you feel the tutorial.
Thanx,
Ketan Mujumdar

Advertisements
  1. February 8, 2011 at 4:04 pm

    nice! great thing to learn. Is it supported in blogspot too?

  2. Nitish Poojari
    February 8, 2011 at 4:05 pm

    Nice Will Try This !!

  3. February 8, 2011 at 4:32 pm

    @puneet No blogspot do not allow to edit their files 😦 . but wordpress is dam customizable .

  4. February 8, 2011 at 4:32 pm

    @nitish Hey nakki try kar its awesome 😀 and easy heheh

  5. February 8, 2011 at 8:20 pm

    wow buddy great to see you having your own blog very cool…

    • February 8, 2011 at 11:05 pm

      hehe are nahi just a pure technical blog hehe just i had faced many problem while learnign wordpress hehe .. are i have written on blog abt multiprotocol messenger kuthe send karu tula ??

  6. Apuurva
    February 9, 2011 at 7:56 am

    Hmm…accha..very cool…
    BOUNCER !! hahaha
    But cool….u finally got a wordpress blog !! Copycat…

    • February 9, 2011 at 10:04 am

      Copy cat vagaire kahi nahi huh just coding wise wordpress blogs are mugch more flexible 😀

  7. Aniket
    February 9, 2011 at 5:43 pm

    Nice post Ketan. Keep up the good work.. Cheers !!

    • February 11, 2011 at 11:35 am

      Thanx buddy just try and support for opensource technology 😀

  1. February 9, 2011 at 5:06 pm
  2. February 11, 2011 at 11:41 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: