Until a few years ago, I hadn’t written a single WordPress plugin. I had created and customized many themes for our clients, but for some reason, I kept telling myself that creating a plugin was beyond my capabilities.In hindsight, I couldn’t have been more wrong.If you’ve ever felt this way, let me tell you something. Creating a WordPress plugin is not beyond your capabilities. Anyone that has skills enough to write basic PHP and modify a theme can create a plugin.
Why would you want to create a plugin?
If you’re like I was, you’ve probably been adding functionality to your theme instead of creating a plugin. There are plenty of cases where doing so is fine, but there are also cases where custom functionality is better off being added to a plugin. Why might you ask?You’ve added functionality to your theme that changes the default gravatar to your own custom gravatar. The only issue is, you’ve just changed themes and now that’s gone. If you had added that code to a plugin it would still be there when you decided to switch themes.
We ran into this issue with the Tabata Times multisite network. They use a handful of themes that need to share custom functionality. How do you think we solved that problem? You guessed it, by adding a good chunk of the functionality into a plugin so it is available to all sites on the network, regardless of which theme they are using.
Create your first plugin in five simple steps
I’m not kidding. You can create a WordPress plugin in five simple steps. Let me show you how…
1. FTP into your site
The first thing you’ll need to do is access your site via FTP using the FTP program of your choice (mine is Coda). If you’re not familiar with FTP, I recommend you read up on that before moving forward.
2. Navigate to the WordPress plugins folder
Once you’ve accessed your site via FTP, you’ll need to navigate to the WordPress plugins folder. That folder is almost always located at /wp-content/plugins.
3. Create a new folder for your plugin
Now that you’re in the plugins folder it’s time to create a folder for yours! Go ahead and create a new folder, giving it a unique name using lowercase letters and dashes such as my-first-plugin. Once you’ve done that, enter your new folder and move on to the next step.
4. Create the main PHP file for your plugin
Next, you’ll need to create the main file for your plugin. To do so, create a PHP file within your new plugin folder and give it the same name such as my-first-plugin.php. After you’ve done that, open your plugin’s main file and get ready to do some editing.
5. Setup your plugin’s information
Finally, copy and paste the plugin information below into your main plugin file. Make sure to edit the details such Plugin Name and Plugin URI as they pertain to your plugin.