Create your first WordPress Plugin
If you're reading this, you probably want to create your own WordPress plugin. Or maybe you're just eager to learn. Either way, I'm here to teach you.
In this first part, I will show you how to setup an empty plugin, and how to install it into your WordPress configuration.
What Will I Need?
For creating a WordPress plugin, there's a couple things you'll need:
- Code Editor
I reccommend a code editor called Visual Studio Code. It's great for any type of programming, and it has a lot of useful features that other code editors doesn't. It's free and user friendly. This is a great program for anyone, doesn't matter if you're new, or have been programming for years. VS code will always be my number 1 reccomendation. - A WordPress Installation
I always reccommend a local configuration of WordPress when developing plugins. This makes it way easier to test your plugins, and you can make small changes without reuploading your plugin all the time. A tutorial setting up a local configuration of WordPress will come later, and I will upgrade this post once it does.
And that's basically it! That's all you need when it comes to creating a WordPress plugin. So let's get started!
Plugin Folder Setup
The very first thing you do when creating a plugin, is settingup the folder structure. You will create the folder structure the same way no matter what kind of plugin you're making.
First, create a folder with a name of your choice. This name should somehow represent what your plugin is about. The name should not contain any spaces, or any big letters. This will make it easier to keep the WordPress folder structure nice and clean. In my example, I will name this folder
"tutorial-plugin".
"tutorial-plugin".
Now that you have a folder with a suitable name for your plugin, it's ready to get some content into it.
Open up the folder, and create a .PHP file with the same name as the folder. It's very important that the .PHP file has the exact same name, unless WordPress won't be able to read it, and the plugin wont run.
To create a .PHP file, simply create a new text document, and name it the same as the folder name.
Now with your .TXT file, open it up, click "File", and then "Save as" (or CTRL + SHIFT + S). Now on the bottom of the new window that popped up, change the filetype from "Textdocument (*.txt)" to "All files", then add ".php" to the end of the filename.
Click "Save", and you should see a PHP file along with your text document inside the folder you made. You can go ahead and delete the text document, so you're only left with the PHP file.If you have a local WordPress installation, you can throw this directly into your WordPress plugin folder. This will be located at "wp-content -> plugins".
Plugin Header
Now we have created all the files we need to make our first plugin. For more complex plugins, you would want a lot more folders inside that folder again, and the file structure would be completely different. But we're going to stick to this for now, as we won't be making anything complicated.
Open the PHP file in your code editor to continue the tutorial. Simply right click the PHP file, hover over "Open with" and then choose your code editor.
Now we are inside the PHP file, and ready to make the plugin functional. We won't be doing that in this part, but we will create the header (the plugin information that is visible on the WordPress installation)
and upload it to the WordPress installation.
and upload it to the WordPress installation.
![]() |
| This is the plugin information we will make in this part. |
To start creating your plugin, and making it visible in the plugins panel, we will need to create the plugin header. The only requirement WordPress has for this header, is that it conatins a Plugin Name. Without this, WordPress will not read or show your plugin.
To do this, first create a PHP opening tag, and a PHP closing tag. This is to show WordPress that everything we write in between those tags, should be read as PHP code.
Everything of our code will go in between these two tags, including the plugin header, which is the next step.
I named my plugin "Tutorial Plugin", but you can name yours whatever you want.
Now, this is already enough to make WordPress recognize your plugin and show it. You can now upload this plugin to your WordPress installation, and it will show under your plugins list. Or if you have the plugin folder in your local WordPress installation, you should be able to just save the PHP file, and it will automcatically update and show in your installation.
To upload your plugin to WordPress, you will need to convert your plugin folder to a .ZIP file. To do this, just simply right click on your plugin folder, and press "Compress to a .ZIP file".
You should get this zipped folder (hah, get it?) with the same name as your plugin folder.
Now go to your WordPress installation, and open the "Plugins" admin site. Then at the very top of the site, next to the title, you should see a "Add new" button, Click that to open the online plugin libriary.
Then when the new page opens up, then again at the very top of the page, next to the title, you press the "Upload Plugin" button. This will prompt you with a file input form, where you will upload your zipped plugin folder we created earlier.
Once you've uploaded the file, press the "Install Now" button to install the plugin. You should then get a window where it asks you to confirm the installation, then press yes.
And voila! You should now see your plugin in the WordPress Plugins list. This means that you successfully created a plugin with the correct folder structure and plugin header.
You have the option to activate the plugin, but since we haven't added any functionality to the plugin, nothing will happen.
In the next parts, we will experiment with different functions, adding more heading information, and more!
Feel free to leave a comment if you have a problem, or if there's anything you wish to see in future posts!
Thank you for reading this, and I hope it helped you a little on your way to creating your first WordPress plugin.
.png)









.png)

Comments
Post a Comment