
WordPress is an awesome publishing tool, and one of the best features is its flexibility to customize its core functions with plugins. The simplest definition of a plugin is:
A plugin is a snippet of code which is used to extend the functionality of WordPress.
And one of the nicest things about plugins is that the barrier to entry is extremely low. It takes very little technical knowledge to make your first plugin!
What Will We Learn In This Tutorial?
Let’s take a look at the key points of the tutorial.
- Learn key tools necessary to set up a plugin development environment
- Develop our own simple plugin which will insert an author’s info section in the end of each article.
- Look at some core plugin tools, like hooks and conditional comments.
- Share some great resources for plugin development.
But before we get started, let’s just look at a few reasons you might want to read this post.
Why develop a plugin?
Skip the Repetitive Tasks
For example, to avoid the inconvenience of inserting the link of author’s page manually each time while publishing a post, it would be more beneficial if this subroutine is embedded in a plug-in that will involuntarily perform the task
Earn Money
Not everyone is a code junky. There are a lot of customers who would prefer to pay a handsome amount to some developer for building a plugin that will meet their needs.
Get Back Links
Everyone knows that backlinks are cash of online world. If you have develop a nice plugin that creates some buzz in the community, you’ll get plenty of people linking back to you.
For Fun!
Coding can be quite enjoyable, especially when the end product is a feature that you yourself have always wanted. And it doesn’t hurt to be giving back to the community either!
Now, onto the tutorial!
Setting up the Environment
This first step isn’t essential, but definitely recommended as it will speed up your development time immensely!
We’re going to install WordPress on our own computer, so we don’t have to worry about uploading files to a webserver every time you change something. Thankfully, this is pretty easy to do! Xampp can be used for PC and MAMP for Mac.
After this grab a copy of WordPress and install it on your new localhost server. And you can use your favorite text editor (I’m using Notepad++ because of its nice syntax highlighting).
Mozilla Firefox with Firebug add-on installed is also a necessity. Firebug is an awesome tool for developers; it allows editing and debugging code in real time.
Resources:
Now let’s mess with some code.
Coding The Plugin
We need to choose a unique name for our plugin. If it is going to be released to the public, it should not match any plugin in the WordPress repository. I have chosen the name “PBD Author Info” for our tutorial.
The first step in creating the plugin is to create a folder with the plugin name in the wp-content/plugins folder. In our case, it is named PBD_Author_Info.
Now, we create the core file which contains standard plugin header information. The file can be named anything you want as long as it is in the plugin’s own directory.
If the file is placed directly into wp-content/plugins folder (i.e. You skipped out the folder step above!), then it must have a unique identity. In our case, let’s make a file called “PBD_Author_Info.php” containing the following code.
1 2 3 4 5 6 7 8 9 | <?php /* Plugin Name: PBD_Author_Info Plugin URI: http://www.problogdesign.com/tag/wordpress/ Version: 0.1 Description: A Plugin that will add an author info section at the end of your posts. Author: Saad Hameed Bassi Author URI: http://www.crispytech.com */ |
Line 1 just means that we’re going to write some PHP code. The remaining code is enclosed in /* */, because it’s a comment (Not executable code). This is the standard plugin information header. WordPress would be unable to recognize the plugin without this info.
Now if you visit the installed plugins page, WordPress is able to recognize the plugin.

We can activate the plugin now if we like, but of course it’s not going to do anything because we haven’t taught it to yet! Let’s fix that.
We are going to define a function called author_info which calls the section holding author info.
1 2 3 | function author_info() { ?> |
Now we will add some regular old HTML and WordPress template tags to build our author info section.
1 2 3 4 5 | <div class="author_info"> <?php if (function_exists('get_avatar')) { echo get_avatar(get_the_author_email(), '65' ); }?> This post was written by <?php the_author_posts_link(); ?>.<br /> <?php the_author_meta('description'); ?> </div> |
The functionality has been characterized using WordPress template tags. The three template tags I used here are:
get_the_author_email()grabs the author email from his profile page.the_author_posts_link()shows author’s public name with a link to all the posts published by the author.the_author_meta('description')is used to pull out the author’s bio from his profile page.
Lastly, let’s close up our function>
1 | <?php } ?> |
On top of that, we’re going to add in some CSS styles to control the appearance of our HTML. We’ll need to use the PHP “echo” command to tell the plugin to write the CSS to the webpage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php function stylesheet() { echo " <style> .avatar { float:left;background-color: #9A9B9B;padding: 4px;margin: 0 4px 0 0;display: inline; } .author_info { color: #666;background: #DDDDDD;padding: 8px;margin:0 0 6px 0; } </style> "; } |
Now we will define the main function called display_author_info. This function is the one that is loaded when the plugin file is loaded, and we’re going to load the 2 functions we’ve just written from this one.
1 2 3 4 5 | function display_author_info() { if (is_single() ) return author_info().stylesheet(); } |
is_single simply conveys to WordPress to execute our function only when it is showing a single post. is_single is one of the core WordPress conditional tags, there are a number of others you can use in your plugins.
At the moment, we can test the output of plugin by adding the following code to our single.php file after the content:
1 | <?php if (function_exists(display_author_info)) echo display_author_info; ?> |
The above code simply calls our plugin function.
The plugin is almost ready, but we could make it more user friendly by automatically adding the plugin code for users, so they don’t have to edit their theme files at all.
WordPress hooks provide a way of doing this. Hooks provide a way of telling WordPress to automatically load our plugin at a certain point while it is building the rest of the webpage.
There are two types of Hooks. According to the WordPress Codex:
Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.
And the definition of Filters according to WordPress codex is
Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
We will use a filter hook called comments_template to hook the comments on a single post. This filter will ensure that WordPress launches display_author_info when it is loading comments template and append the author info section between the post content and comments.
1 2 | add_filter('comments_template', 'display_author_info'); ?> |
Our Finished Code
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <?php /* Plugin Name: PBD_Author_Info Plugin URI: http://www.problogdesign.com/tag/wordpress/ Version: 0.1 Description: A Plugin that will add an author info section at the end of your posts. Author: Saad Hameed Bassi Author URI: http://www.crispytech.com */ function author_info() { ?> <div class="author_info"> <?php if (function_exists('get_avatar')) { echo get_avatar(get_the_author_email(), '65' ); }?> This post is written by <?php the_author_posts_link(); ?><br> <?php the_author_meta('description'); ?> </div> <?php } function stylesheet() { echo " <style> .avatar { float:left;background-color: #9A9B9B;padding: 4px;margin: 0 4px 0 0;display: inline; } .author_info { color: #666;background: #DDDDDD;padding: 8px;margin:0 0 6px 0; } </style> "; } function display_author_info() { if (is_single()) return author_info().stylesheet(); } add_filter('comments_template', 'display_author_info'); ?> |
And that is our basic plugin complete. It doesn’t do a great deal, certainly not anything that you couldn’t do easily enough in your theme anyway, but hopefully we’ve demonstrated some of the core features of plugin development to you!
Resources for More Complex Plugin Development
Now that you’ve found your feet with plugins, it’s time to start building that up knowledge. Here are some of the best recommendations we can give you, in 3 categories.
- Beginner
- Intermediate
- Advanced
Beginner

Writing a plugin – WordPress Codex
This ultimate resource for Newbies. The extensive WordPress codex describes the development procedure in detail. You may find it a little dry though, and other resources which work through real examples may be more useful. The codex will always be an invaluable reference while you’re coding though, nowhere else has anything like the amount of information the codex has on different WordPress functions!

Free e-Book: How to Write a WordPress Plugin
Very Useful ebook for WordPress plugin developers. This twelve part series illustrates the process from creation of a plugin, right through to promoting it. Well worth working through if you have the time!
Developing Plugins for WordPress (Singapore PHP User Group 2008)
A video presentation from Lester Chan (one of the best known plugin devs around!) on developing a WordPress plugin.
This screencast shows you how to make a very simple plugin which will replace foo with bar. A beginner’s guide from Mark Jaquith, who is a core developer for WordPress.

A Crash Course in WordPress Plugin Development
A simple tutorial explaining the implementation a Digg button and adding some formatting to posts.
Intermediate
The slides from Matt Martz’ presentation at WordCamp NY09.You can also watch the video here.
This article instructs on how to build a widget plugin that queries a given number of blog posts scheduled for the future.

Wordpress Plugin Development Tips And Tricks
A very handy article for WordPress plugin developers about some useful tips and tricks.

Top 10 Most Common Coding Mistakes in WordPress Plugins
Ozh, a very famous wordpress plugin developer writes about how to make your plugin error proof from the most common errors.
Advanced

How To Design And Style Your WordPress Plugin Admin Panel
An advanced tutorial on how to style your WordPress plugin settings panel.

Make your WordPress plugin talk AJAX
Some nice examples of using Ajax in WordPress plugins by Irish WordPress Developer, Donncha O Caoimh.

A very useful guide on how to implement shortcodes in plugins.

Create a custom WordPress plugin from Scratch
This tutorial elaborates the development of a plugin that shows random products from an external OSCommerce database.

Create a Plugin with its Own Custom Database Table
A tutorial covering the creation of a plugin which has its own database table. Follow this tutorial if you want to learn how to validate a database table if your plugin is writing entries to it.
Conclusion
The guide above should give you the most basic steps to building your own plugin. It really is that easy to start!
And hopefully with all of the resources we’ve listed, you’ll be able to expand that into a much more complex plugin someday! If you know of a great tutorial or plugin resource we’ve left out, share it with us!

Custom Search
Keith Davis (60 comments)3 December 09
Hi Saad
The title says it all “A Novice Guide to WordPress Plugin Development”.
I guess at the moment I’m not even a novice! Still I’m a big believer in making a start. We all have to start somewhere and perhaps this time next year I’ll be thinking… Where’s that novices guide to Wordpress plugins?
Who knows.
Michael Martin (1319 comments)3 December 09
The first steps are always hardest. Hope the post does come in handy someday!
Micheal (2 comments)3 December 09
Very nice article saad.I really loved the example.And your explanation of code.
Bill Robbins (2 comments)3 December 09
There is a great plugin framework available in the plugin directory at
http://wordpress.org/extend/pl.....-framework
It provides lots of well documented code and useful resources to help in developing plugins. It could be helpful to people looking to write their own first plugins.
Michael Martin (1319 comments)3 December 09
That’s a great looking tool Bill, perfect for people who like to learn by working on a real project and tweaking things to see how they work. Thanks a lot for sharing!
Saad Bassi (8 comments)4 December 09
Bill I checked that before writing the tutorial but i think it will be advanced for beginner users.It is best for people who like hit and trial method.Moreover my opinion on it is if a person don’t know what a filter is then probably he can’t work with the framework too.Moreover the framework is complex for a simple plugin.
designfollow (8 comments)3 December 09
very useful
thank you
denbagus (7 comments)3 December 09
nice concept to build wordpres plugin
TheWebTuts (1 comments)4 December 09
Tutorial added to thewebtuts.com
Sharninder (5 comments)4 December 09
Very nice ! I’ve been trying to implements a couple of plugins for my blog but always had some doubts about filters, actions and hooks. This post and all the awesome resources linked from it should help a lot. Thanks Saad
Luigi | UPrinting.com (1 comments)5 December 09
The great thing about developing a plugin is skipping repetitive tasks. Doing the same task can really waste time right?! So thank you for this post.
Saad Bassi (8 comments)5 December 09
I am happy that you people found it useful
Salman Aslam (1 comments)5 December 09
Very nice tutorial man. Appreciate your work and effort
Greg (6 comments)5 December 09
Useful even if some tips have already been posted in my blog.. Thanx !
Saad Bassi (8 comments)6 December 09
Greg, i didn’t understand you.What are you trying to say?
Social Media Marketing Is Here To Stay (1 comments)6 December 09
Oh man that was some killer information and well planned out and laid out. I read though it and there where about 2 things I did not even think about doing that I can now do when starting up. THANKS!
joshua strebel (1 comments)6 December 09
Plugins are where it is at. A couple weeks ago at PHXWordcamp I participated in a roundtable discussion panel with Mullenwag where we the concept came up more than once. WP is fairly lightweight and should stay that way. People asked about adding e-com or more cms functionality to the core.
Matt mentioned the plugins and themes are more suited to extending use, than adding bloat to the core. I personally agree, thinking the plugin system is ideal for expanding wp functionality. I also feel there is huge opportunity for the commercial plugin market like we are beginning to see, so get coding
Keith Davis (60 comments)6 December 09
Hi Joshua
Agree… keep the core lightweight (if it is classed as lightweight?) and add all the extras via plugins.
That way you can do as much or as little as you like.
As for CMS… some of the themes out there add great CMS capabilities.
I hope that one day I will be able to say that I took part in a roundtable discussion with Matt Mullenwag LOL.
Saad Bassi (8 comments)7 December 09
Totally agree with you joshua.If you can make custom functions and plugins you can make any type of website with wordpress.WordPress will be good as long as it will remain good.It will fail,if it will become to try something like joomla.I know making websites and using wordpress as a cms is a little bit tricky.but we can done with a nice use of page templates
Saad Bassi (8 comments)7 December 09
Totally agree with you joshua.If you can make custom functions and plugins you can make any type of website with wordpress.WordPress will be good as long as it will remain wordpress.It will fail,if it will try to become something like joomla.I know making websites and using wordpress as a cms is a little bit tricky.but we can done it with a nice use of page templates
Design Ideas (1 comments)7 December 09
Very useful article for my developers
Zugvogel (1 comments)7 December 09
This is really a very helpful resource for every ongoing wordpress plugin developer.
Thanks!
handbags (11 comments)9 December 09
helpful resource for me.:)
Julius Kuhn-Regnier (5 comments)9 December 09
cool tutorial
I always wanted to write my own plugin but I actually never tried it. Maybe this will help me in getting started.
J Themes (8 comments)10 December 09
Dang, this is a very comprehensive guide. I have always wanted to develop a WordPress plugin. Now I know where to start.
malowanki dla dzieci (1 comments)13 December 09
Interesting article, great plugin Saad
Joomla Bear (4 comments)14 December 09
Great tutorial – demystified a few things for me. I’m almost loving Wordpress more than Joomla currently
seo your blog (2 comments)14 December 09
This is an useful post, I have bought a book from Amazon by Vladimir Prelovac on how to develop wordpress plugin, I am really finding it useful, I would highly recommend it for anyone who is serious about developing plugins for wordpress.
chris (18 comments)16 December 09
perfect. Instead of inserting a lot of code, I can now call that code and insert it anywhere. thank you
Website laten maken (9 comments)17 December 09
This is what I call a great guide! Very well done, I will bookmark this one!
links of london bracelet (3 comments)25 December 09
a great guide! i need to learn more code.
AJ Clarke (2 comments)25 December 09
I just started learning how to develop plugins. There are some great itps here. Thank you!
WPExplorer (6 comments)27 December 09
*tips
Rajesh (3 comments)26 December 09
Nice one. Keep up the good work
Jar kko (2 comments)8 January 10
Plugins are very interesting field. Thanks a lot for this post! It was very interesting.
Aashish (3 comments)11 January 10
Gr8 post and gr8 collection, It helped me to furnish my Wordpress Front Page Banner Plugin. Keep it up!
preethi (2 comments)12 January 10
It helped me a lot, thanks
the_guv (1 comments)13 January 10
utter
ruddy
total
.. class
Saad .. thank you.
SJL Web Design (10 comments)19 January 10
Thanks for the great article on pluggin development, I keep getting different ideas for pluggins but I never knew where to start developing.
zico (7 comments)26 January 10
Great job. Very helpful tutorial on plugin development. Thanks.
Altinkum (2 comments)30 January 10
hm – I am at the moment surfing the web trying to learn more about wordpress. Just got a new blog and whilst I love wordpress, I think I will leave the above to my webmaster. Most of it just went straight over my head.
Having said that I admire all the work that people put into wordpress. It has made it the best blogging platform around.
Piyush Shekhar (1 comments)21 February 10
Nice tutorial. Will try and make a new plugin in a few days !
cheap florida vacations (2 comments)22 February 10
another great post!
car wraps (2 comments)22 February 10
This is my goal for next month. Tnx