Recently I realized I had a problem. I’ve been coming across a lot of very useful bits of code that you can put into your theme’s functions file.
That may not sound like a problem, but it is. Because these files are tied to your theme, if you ever want to use them again on a different theme, you have to go digging around for the bits of code and then manually add them again to your new theme.
The answer, it seemed, was to turn these bits of code into simple plugins that I could easily install on any site, and of course, with any theme.
How Hard is it to Make a Plugin?
I am no coder. Let me say that up front.
In fact, let me repeat it: I am no coder.
I want to establish that here and now because if I can do this, then I assure you, you can do this. We aren’t trying to make some super complicated plugin here. In fact, we aren’t even trying to make a “simple” plugin.
What we’re aiming for is super simple. Extra super simple, in fact.
And on top of that, these plugins are for your own personal use, so you don’t need to worry about impressing anyone, dealing with unhappy users, getting your plugin into the WordPress Plugin Directory, etc.
Featured Plugin - WordPress Ecommerce Shopping Cart Plugin
Tools You Will Need
The only “tool” you will need is a text editor. There are free text editors you can download, or you can simply look on your computer (Notepad for Windows, TextEdit for Mac).
The free text editors out on the web will give you a few more options if you’d like to use them for other work, but to make these super simple plugins, what you have on your computer will do.
I’ll be using Notepad in Windows for this tutorial.
How to Make a Plugin
At the simplest level, there are only two parts to a plugin:
- The plugin header information
- The code for the plugin
For this tutorial, I’m going to make a simple plugin for some code I found that automatically puts a login or logout link on your Custom Menu. I blogged about it here – login/logout link on menu.
Featured Plugin - WordPress Q&A Site Plugin
The Header Information
For the beginning of your plugin, you need to open with a PHP tag like this:
<?php
Then you need to include some header information. Start your header section like this:
/* Plugin Name: Name Of The Plugin
The truth is that the name of the plugin is the only thing that’s required here. So, if you wanted to, you could end your header section right there by closing it off with */ (don’t forget to close it off).
So your entire header section could look like this:
/* Plugin Name: Name Of The Plugin */
WordPress.org gives a mockup of what a complete header section might look like here. This is what they suggest:
<?php /* 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 */ ?>
All that is fine; however, since we are only making this plugin for our own personal use, there’s a lot of stuff there that we don’t really need.
For later convenience, it might be nice to have a description that spells out what the plugin does (you may forget after time). And it may be a good idea to include a link or two that goes to where you found the code in case you ever need to find your way back there for some reason.
And so that’s all we’re going to include here.
- The plugin’s name
- Description
- Link to original source – Actually, I’m going to include two sources – where I found the original code and my blog post here at WPMU. I’m going to include these links in my description section, so I can describe where they go.
And so this is what the top part of my plugin file looks like at this point:
<?php /* Plugin Name: Login Logout on Menu Description: This plugin puts a login or logout menu on your WordPress Custom menus. Original code found <a href="http://vanweerd.com/enhancing-your-wordpress-3-menus/#add_login">here</a>. More explanation <a href="http://wpmu.org/how-to-add-a-loginlogout-link-to-your-wordpress-menu/">here</a>. */
Of course you could put more info in if you like. You could put yourself as the author, for example, just to remember that this was a plugin you created. And you could also use the Plugin URI spot to put your link to the original code.
As this isn’t meant for public consumption, whatever you like goes, as long as you have a name for your plugin.
The Code
Next comes the code. And all we need to do is drop the code into the body of the file.
***NOTE***
You will notice in the suggested header that WordPress gives, there is a closing PHP tag. It looks like this: ?>
You need to make sure that your actual code goes BEFORE this tag.
In fact, in order to prevent the mistake of putting something after that closing tag, you can eliminate it completely. As long as you have the opening PHP tag (<? php), that’s enough.
Featured Plugin - WordPress Appointments Plugin
The Completed Plugin Code
After dropping the code into my file, the completed plugin file looks like this:
<?php
/*
Plugin Name: Login Logout on Menu
Description: This plugin puts a login or logout menu on your WordPress Custom menus.
Original code found <a href="http://vanweerd.com/enhancing-your-wordpress-3-menus/#add_login">here</a>.
More explanation <a href="http://wpmu.org/how-to-add-a-loginlogout-link-to-your-wordpress-menu/">here</a>.
*/
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout('index.php');
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= '<li>'. $loginoutlink .'</li>';
return $items;
}
Saving Your File
Believe it or not, saving your file may be the most complicated step in the whole process. The key point to remember is that you need to save your file with a .php extension.
If you’re using Notepad on Windows, and it refuses to save as a PHP file, then just make sure you put the name of the file in quotation marks when saving it.
For example, I saved my file in this way (WITH the quotation marks):
“login-logout-on-menu.php”
Featured Plugin - WordPress Newsletter Plugin
Zip Your File
After you save your file, you’ll need to zip it if you want to be able to upload it through the WordPress admin area. Just zip the file itself. Do NOT put it into a folder first.
Upload and Activate
After your file is zipped, you’re finished. You can simple upload it and activate it as you would any other plugin.
Troubleshooting
If your plugin doesn’t work for some reason, these are a few things to check:
Make sure the code works to begin with.
- Before making your WordPress plugin, put the code into your functions.php file to check it first. After you’ve checked it, remove it from your functions file, or it will conflict with your plugin.
Make sure all your code is correct.
- Start with an opening PHP tag (<? php)
- Don’t put code after a closing PHP tag (remember you can actually eliminate the closing PHP tag: ?>)
- Make sure you open your header with /*
- Make sure you close off your header with */
- Make sure you copied the original code correctly
- Make sure the original code doesn’t call for another action, such as placing more code inside of your theme files, etc.
Make sure you’ve saved your file with a PHP extension.
That’s It!
And that’s all there is to it. I’ve tried to go through each step here and some possible problems you might run into, but really it boils down to a few simple steps:
- Put a header with at least a title in your plugin file
- Drop in the functions file code
- Save your file as a .php file and then zip it
- Upload and activate it



Now that is super simple… I’ve always avoided trying to create a plugin but after reading this I’m going to give it a shot… I’m not a coder either… ;)
Thanx for the great info…
Linda =}
Linda – I would say, “Good luck,” but I don’t think you need it. All you need is some working code. :)
I create my first plugin – Marvelous!
I’m excited to make my first subnav link with this knowledge!
Nice, EnPassent. … No stopping you now!
That’s a great tutorial. It was really easy to follow.
I’ve been looking for a way to build my own plugins for WordPress after reading the new book by Jason Fladlien. He talks about how to go about getting it outsourced cheaply, but doesn’t get into the basics of making it yourself.
Even though I wish it had this in his guide, he does go onto how to market and sell your WordPress plugins. That made it worth it for me.
I want to create or find a plugin to overlay affiliate links on embedded YouTube videos. Any ideas?
“I want to create or find a plugin to overlay affiliate links on embedded YouTube videos. Any ideas?”
Not sure about that, although I’m guessing there’s probably something out there.
Yeah I’ve seen it as a widget. But it makes it look tacky since it’s free and advertising for the widget. There are so many plugins out there, it’s tough to find that one specific plugin. :)
I think I’ll have to just create my own.
it’s not a great idea to create plugins without coding knowledges.. The net it’s full of deprecated codes.. and if the code isn’t made well or updated, you will be feed for hackers with Code Injections.
That’s true, Marko. But MANY MANY MANY plugins made by people with plenty of coding knowledge eventually get abandoned somewhere along the line. In fact, I’ve even paid for plugins that were abandoned.
Can you verify my statement for clarification and understanding for me, please?
Following this tutorial as is will result with a single file within the Plugins directory when looking at the file structure within my website.
If I wanted to make it look like all the other plugins and be in its own “folder”, I would simply need to create a folder and place the file into it prior to zipping the entire package and then proceed with uploading and installing in my site.
Then once installed it would appear as a folder in the the Plugin directory and within it, the file that makes the plugin work, correct?
Kerry – Yes, that’s right. You could zip a folder instead of the single file.