WordPress Plugin Development Tutorial – Part 1 • twoggle

Log in

Sign in with your email address and password:

No account? Sign up here.
Forgot your password? Reset it here.
Didn't receive account confirmation email? Request a new one.


WordPress Plugin Development Tutorial – Part 1

So you’d like to develop a WordPress Plugin? Well, look no further – in this tutorial I’ll show you step-by-step how to create a WordPress plugin that you can use yourself or distribute for public use. We are going to look at plugins from both a functional and structural perspective. We’ll start with the plugin file packaging, then move onto API hooks that your plugin uses to interact with the WordPress core (which allows your plugin to integrate into the various WP editing, management, and display processes). Finally, we’ll look at how to publish our plugin for others to use. As an example, I am going to create a plugin from scratch, which will alter the content of WP posts before they are displayed to the user. The goal with this plugin will be to let the user insert html/javascript code into your post’s content in a variety of different ways: At the top of the post, at the bottom of the post and in random locations within the post, specified with a merge field. I’ll go ahead and call it the ‘Content Enhancer‘.

WordPress Plugin Development Tutorial – Part 1

1. Create The Plugin Folder Structure

The first step in creating a new WordPress plugin is to create a folder for your plugin, inside the wp-content/plugins folder. The folder name you pick should be descriptive of your plugin so it’s easy to identify your plugin in the plugins directory (since all plugins live in the same folder, your folder name has to also be unique). It’s always a good idea to maintain a clean folder structure in order to keep all similar files together. So if you’re going to use images on your plugin, put them in the /images folder inside your plugin folder. Here’s a standard folder structure for a WordPress plugin: Top folder: /my-unique-plugin-name

  • my-unique-plugin-name.php  – Base plugin PHP file
  • uninstall.php – Uninstall file
  • /js – Folder for javascript files
  • /css – Folder for css style sheets
  • /includes – Folder for any PHP includes
  • /images – Folder for plugin images

We highly recommend using the above folder structure during your plugin development since it will keep your plugin organized over time. In my case, the plugin folder will be called ‘content-enhancer’ and the main PHP file content-enhancer.php.

2. Create The Plugin Header

All WordPress plugins require a valid plugin header. This header is defined at the top of your main PHP file (in this case, content-enhancer.php as a PHP comment:

Note: Although the Plugin Name is the only required plugin header (the rest is optional), it is highly recommended to use the rest of the header information. This information is used on the Manage Plugins section in the WordPress admin panel.

Plugin Licence

If you plan on releasing your plugin to the public, it is a good idea to include the software licence that the plugin is released under just below the plugin header. A licence block in the comments will state that there’s no warranty, which will protect you should someone decide your plugin destroyed their website! Here is a standard GPL licence, which the majority of WordPress plugins now use (simply include this, within the commented section, underneath your plugin headers):

So now we have the basic structure in place for our custom plugin. In the next part of this tutorial series, we’ll look at how to actually make this plugin do something useful.  In WordPress Plugin Development Tutorial – Part 2, we’ll continue the ‘Content Enhancer’ plugin development …


Submit a Comment