We’ll waste no time and jump in right away. We’ll be discussing what a wordpress plugin header is and how to implement one. We’ll also learn some simple WordPress guidelines you should follow.
Creating A WordPress Plugin
WordPress stores all of it’s plugins inside of www.yoursite.com/wp-content/plugins/. Inside this folder, you’ll find some plugins already installed by default. You’re allowed to store all files inside the plugins folder, but it’s not recommended you do that. You should create a folder inside the plugins folder for your plugin. This way, any other plugins won’t accidentally overwrite any of your plugin’s files.
Naming Your Plugin
It’s important that when you name your plugin, you give it a really unique name. There are thousands of plugins and if a user uploads a plugin with the exact same name as yours, then it’ll overwrite all your work and it’ll cause problems. So, how do you avoid this? Simple, make sure to search WordPress’ plugin directory and check if the name you’ve chosen matches any of the plugins inside the directory. The WordPress plugin directory can be found here.
For this example, we’ll be naming our plugin wpTemplate because we’ll be creating a template that’ll be a base for any future plugins we create. So, create a folder named wpTemplate inside your plugins folder.
Creating the file
Now, we must create the file that’ll be the heart of our plugin. It’ll contain the WordPress plugin header. You only need 1 file for a WordPress plugin to function. Of course, you should be organized and separate all your code in different files. It’s common practice to name the main file the same name as your plugin’s name. So, if our plugin is named wpTemplate, then our file will be named wpTemplate.php.
I’ll be honest, I don’t like naming my file after my plugin. I prefer naming the file index.php because it seems more clean and easy to spot. For this reason, I’ll be naming my file index.php. You don’t have to do this, you can follow the norm and name your file wpTemplate.php. If you do name your file after your plugin, then create an additional file named index.html. This is a security measure you should take so that hackers don’t see the structure of your plugin.
WordPress Plugin Header
Now, let’s get to the main part of this tutorial which is the WordPress plugin header. We’ve followed all the correct steps so far in order for our plugin to be considered a real WordPress plugin.
The WordPress plugin header simply contains information about our plugin such as the name, version, Author, description, etc. Enough talk, let me show you what the header file looks like.
* Plugin Name: WP Template
If you did everything right, go to your WordPress dashboard and go to plugins > Installed Plugins. You should now see your plugin.
Don’t be afraid to click activate. Nothing bad will happen! Your plugin is now live. Now, of course it doesn’t look like the other plugins and it doesn’t have any of that additional information like the other plugins. The only thing WordPress requires is to have that simple file with that simple code. Let me break it down what’s happening.
In your code you’ll notice that the WordPress plugin header information is wrapped in comments. You can use single-line comments or block comments. Then, you have to type Plugin Name: [insert name here] in the comments.That’s it! WordPress takes care of the rest of reading your file and checking whether or not it’s a plugin. So, let’s take it to the next level and add more information about our plugin.
* Plugin Name: WP Template
* Plugin URI: http://jaskokoyn.com
* Description: A Basic WordPress Plugin Template
* Author: Jasko Koyn
* Version: 1.0
* Author URI: http://jaskokoyn.com
Whoa! A couple of things to take in here. Let me explain each one.
- Plugin URI: – The link to your plugin. This would be the link to where users can find more info about your plugin
- Description: – A short and brief description about your plugin.
- Author: – This would be your name.
- Version: – The current version of your plugin.
- Author URI: – A link to your personal website or company.
You don’t need to include the above information. The only thing you need is the Plugin Name, but it’s highly recommend you include the other info as well. Of course, there’s more info you can put in your plugin header such as license information, network, text domain, but those are only needed for certain events. We’ll discuss those later, but for now, it’s not necessary. You should get what you see below.
This concludes our tutorial on how to create a wordpress plugin header. As you can see, it’s easier than you think. Why don’t you take a break before moving onto the next tutorial. If you need more information about the WordPress plugin header, go here.