How To Create a Plugin For Your WordPress

how-to-write-wordpress-pluginWordPress is a very powerful blog and cms php script built following W3C standards for XHTML and CSS. It also allows plugins to extend the core functionality of your weblog. A large number of user-developed plugins are already available and can be used to do virtually many things you want to. But for most bloggers, will do something changes to customize our wordpress system—usually we modify the theme files to do what we want, so when theme be changed, we must do the same changes again. If we can write a plugin include these changes, what we need to do is only click “active”, isn’t it?

We can download a plugin from, open the script files to learn how to write a plugin. But for many wordpress beginners, that’s too complicated. The following is a tutorial on how to create a simple wordpress plugin. The first step, this plugin do nothing, and the second, we will add a function to analytics traffic. And next, then you can add what you want.wordpress-howto

Step 1. Copy the following code save as a file, for example: ntt-plugin.php

Plugin Name: ntt-plugin
Plugin URI:
Description: ntt’s custom plugin
Version: 1.0
Author URI:

Description: The top of your Plugin’s main PHP file must contain a standard Plugin information header, this header information lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run. Above is the header format, you can change to yours.

Now, you can upload ntt-plugin.php to wp-content/plugins , and login your dashboard, click Plugins on the left sidebar.  oh, what have you seen? Yes, it has been listed under Plugins section.But now this plugin can do nothing even you active it because we code nothing.


Step 2. Write the function for your plugin

This sample can add your site analytics code on your footer section:

function site_analytics() {
	echo 'Place your site analytics code here.';

add_action('wp_footer', 'site_analytics');

Re-upload ntt-plugin.php and overwrite, active this plugin. Then open your site with browser, right-click mouse, try to view html source code please. You can find your analytics code have been added on the footer. Now, you can try to add the source code what you want to do,then your customized plugin is born, simple? :)

Other related tutorials for advanced: summary of “Seven reasons to write a wordpress plugin”, it is also a very detailed tutorial on how to create a plugin.

1. You like a plugin’s idea, but don’t like the plugin’s implementation

2. You want to modify existing plugin code

3. You want to extend a plugin

4. You want portable theme code

5. You are a theme designer

6. You want to make money

7. You want incoming links

This tutorial explains how to write a plugin which will count search engine bots visits.

More and more plugins are starting to use AJAX techniques, if you want write a AJAX plugins, Using AJAX with your WordPress Plugin should beseem you.

If your plugins need “Saving Options”, you can read this tutorial.

Before writing your plugins, if you can read Top 10 Most Common Coding Mistakes in WordPress Plugins, I think most common mistakes like following can be avoided.

1. It’s not a plugin, it’s a mess

2. Way too generic function names

3. What? 87 new rows in the option table?

4. You create new tables for what?

5. No uninstall function

If you are a jQuery developer, Simplified AJAX For WordPress Plugin Developers using Jquery should be what you need. This tutorial explains how to use ajax to add that sexy feature which will make your plugin look bit cool.

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

Leave a Reply