Tech 4 minutes read

WordPress plugin development – Beginner’s level

What is a WordPress plugin?

Before we start talking about WordPress plugin development, we must understand what is a plugin. A WordPress plugin is a simple or complex program, with one or more functions, written in PHP scripting language. It can help you customize your WordPress website, and add all kinds of functionality.`

Theoretically, you can run a WordPress website without a plugin, but it will be very limited. So, plugins are essential in creating a WordPress website, because they add extra functionality.

There are free and paid plugins. You can search all of the plugins - here. But sometimes you need to create a plugin of your own, so in the text below we will show you how you can create a very simple and basic plugin.

WordPress plugin development hero image.

What do you need before you start making WordPress plugin?

For WordPress plugin development you will need:

  • a code editor (e.g., Visual Studio Code, Sublime Text, Notepad++, etc.),
  • a working WordPress installation. If you want to create a plugin for your live website, make sure you are doing it on a WordPress staging site. In this way, you can test your plugin, while not affecting your live website. Or you can test it in the local environment.
  • a browser (e.g., Chrome, Firefox, etc.).

Some basics before you start making your WordPress plugin

Step #1: Naming your WordPress plugin

You must come up with a unique name for your plugin, so it won't come in conflict with other plugins. You can always check a WordPress plugin repository, so you can be sure that your name is unique.

One of the methods for naming your plugin is to include what it does in its name. In our case, our plugin will add some text at the end of the posts on the website. So, we will name our plugin "Bottom text for Posts".

Step #2: Creating plugin files

Your plugin can be made of one or multiple PHP files, it depends on what it is meant to do. The primary file is the main PHP file. This main PHP file is like index.php in WordPress theme development.

It is custom to name your main plugin file after the plugin name. In our example, our plugin name is "Bottom text for Posts", so the name for the main plugin file would be bottom-text-for-posts.php. If you want to add a separator in your name, use hyphens ( - ), not underscores ( _ ).

As we mentioned earlier your plugin can be made out of one or multiple files (JavaScript, CSS files, images, etc.), but it is important that all of these files must live in a single directory. So, our files should be placed in a folder named the same as the main file bottom-text-for-posts. After you are finished coding your plugin, you should compress your folder into a zip file (bottom-text-for-posts.zip) and install it on a WordPress website.

Step #3: Add a header to the main PHP file

In the plugin main PHP file header, you should add some information about the plugin you are making.

That information should include the author's name, description, license, etc. It should look like this, this is some standard header look:

Code that is used in creating a WordPress plugin.
Plugin information in the PHP file header

You don't need everything above if you just want to practice. But the header comment must contain the name of your plugin. In our case it is:

Code that is used in creating a WordPress plugin.
Header comment in the PHP file

Creating a WordPress plugin

Name your WordPress plugin

Now, we will follow the steps we mentioned above. First, we need to name our plugin.

We started by looking through the WordPress plugin library and doing a Google search for our name - The bottom text for Posts is available. Let's continue. Open a code editor and add the following code at the top of the plugin's PHP file:

Code that is used in creating a WordPress plugin.
Code to insert at the top of the PHP file

Save the file when you are finished. In our example, our file name is bottom-text-for-posts.php.

Compress your plugin folder

Compress your file and make sure you save your file as a .zip or your plugin won't be installed.

Upload and install your plugin

Upload, install, and activate your first WordPress plugin!

WordPress dashboard - Uploading plugin.
Uploading new plugin

WordPress dashboard - Installing plugin.
Installing plugin

And that's it. Now you can check if your plugin is working.

Great job! You have successfully created your first WordPress plugin!
Do you want to learn more about WordPress plugin development, you can check out this YouTube tutorial playlist.

Since we are talking about plugins, you can read more about plugins in our other blog - WordPress caching plugins overview.