Minimum Required Files for a Plugin

So, you’re thinking of creating a plugin! Or perhaps you’re just starting out with WordPress and are curious where to actually start? Maybe you’re just here for the files? Which is ok too! (psst.. they’re at the bottom).

Tell me more! What are plugins?

In case you are new, let me tell you what a plugin is first of all. And let me do that by sharing my favorite analogy. Imagine WordPress being your brand new house, and then think of plugins as items inside your house. These items in your house all serve different functions and perform various tasks. For example a lamp provides light, and your dishwasher cleans your dishes. In the same way plugins perform various functions within WordPress. Some can extend existing functionality while other can bring brand new functionality to your WordPress powered website.

And there really aren’t any limitations to what you can achieve with WordPress and some well-designed plugins! But let’s get to the nitty gritty.

What do I need?

Unlike when you are creating a theme for WordPress, a plugin only requires a single file, and it is very straight forward, here is what you need.

First select a name for your plugin, and try to make it as unique as possible. If you are planning on uploading the plugin to the WordPress plugin directory then it will have to be 100% unique. Even if you are creating the plugin for yourself it is still a good idea so that you avoid possible conflicts with other plugins that may have similar names.

For our case, we are naming the plugin: Bytepress Minimal Plugin.

If you are creating a small plugin, perhaps only to perform one or two simple actions, then a single .php file in the wp-content/plugins directory may be enough, and it would look something like this:

However if you plan on adding more files and build a bigger plugin, you have to keep them all in their own folder. The folder also has to be named identical to the .php file we just made above, and it would look something like this:

Inside this file you need to add a little chunk of code that tells WordPress all the information you need for the plugin:

/*
Plugin Name: Bytepress Minimal Plugin
Plugin URI: https://byte.press/blog/minimum-required-files-for-a-plugin/
Description: Minimal amount of files and file structure required to create a plugin
Version: 1.0.0
Author: Bytepress
Author URI: https://byte.press/
License: GPLv2 or later
*/

This chunk of code is then read by WordPress and will in turn generate the entry on the plugins page in the admin panel like so:

And there you have it. Your first plugin with the absolute minimum amount of files and code needed.

Feel free to download the plugin file and play around with it yourself.

Written by Jay - November 2, 2017
Last edited - November 7, 2017
Tags:

Comments: