Scroll to top
USA
651 N Broad St, Suite 206,
MiddleTown, New Castle,
Delaware - 19709
Canada
635 Ashprior Avenue,
Mississauga, Ontario,
Canada - L5R3N6
India
34, Shiwanshu Bunglows
Vadodara, Gujarat - 390007

How to start making plugins for WordPress (Beginners Guide)

82 / 100

WordPress is the most popular open-source blog system. Due to its ease of use and extensibility, it is almost a de facto blog industry standard. With their plugin management module, developers are free to build their own custom plugin to add new features. Some examples are page-specific SEO features, photo gallery, spam combating, and more.

Writing your own WordPress plugin is not that difficult if you are a web developer with basic PHP skills. The only thing you will need, coupled with your PHP skills, is some direction, some resources, a little information on how WordPress expects your plugin to behave, and most importantly a great idea.

How to start making plugins for WordPress

A plugin is a simple program, a set of functions, that adds a specific set of features and services that can be executed in different sections of your WordPress site.  we had to rank the reasons we love WordPress, plugins would be near the top of the list. These handy tools let you add all kinds of features to your site in seconds. However, sometimes you can’t find a plugin that meets your needs or you may simply want to try your hand at developing your own solution.

If that’s the case, then you’re in luck. It’s actually considerably easier to create a WordPress plugin than you might expect. In fact, you can create a plugin with just a few lines of code, and you need very little prior knowledge or experience to put together something simple.

Let’s get started about how you can make your own plugins for WordPress.

The Basics of a WordPress Plugin

As the official documentation puts it: “Plugins are ways to extend and add to the functionality that already exists in WordPress.” WordPress itself consists of a relatively small set of features, which are referred to collectively as the platform’s ‘core.’ Plugins are downloadable add-ons, containing files and code that expand or alter the functionality of that core. In fact, the WordPress philosophy states that if a feature is likely to be used by no less than 80 percent of all users, it should be included in the core. Otherwise, it should be a plugin.

Wordpress plugin

For this reason, the breadth of possibilities offered by plugins is huge. You can use them to add opt-in forms, sliders, or pop-ups. They can be very simple or can be incredibly expansive.

This fact means that plugins are one of the most important features of WordPress. They make it easy to add almost any functionality to your site, with no coding or prior knowledge required. There are thousands of free plugins, which you can use without shelling out any cash, or you can opt for premium solutions. What’s more, downloading and installing plugins in the WordPress admin just takes a few clicks.

Difference between Plugins and Themes

Although, themes also add some features and functionality to a site they are different from plugins. A plugin can’t change a website’s design, look and feel but a theme can do everything. You can customize some functionality in themes instead of installing plugins but themes can’t be replaced by plugins.

Difference between WordPress theme and a Plugin

A theme is an external effect like a website’s presentation and design. Whereas, a plugin is an interior effect that adds or removes some functions to a site.

Theme organizes and displays the entire site’s information to display it to the visitors.

If you want to change the appearance of your site by changing your theme, then all the customizations done will be gone (data and information will remain safe). But you can activate or deactivate a plugin whenever you want. It will not affect the site in any way.

Your site speed is mainly affected by the designing of the theme, the number of images, cache power. Several plugins installed and functionality code that exists as a plugin or theme does not contribute to the site’s speed.

It’s better to allow themes to handle the look of a site and plugin to handle how a site should behave. Thus, when the theme changes, all the functionalities of the site will remain there.

How Plugins Work: An Introduction to Hooks, Actions, and Filters

Now, it’s time to get a little more technical. We’ve already mentioned that plugins literally ‘plug in’ to WordPress core. This is done using ‘hooks,’ which enable one piece of code to interact with another. As such, hooks determine when and where on your site a plugin is actually used.

WordPress plugins

We realize that this can be a bit confusing if you’re new to the topic. Therefore, let’s consider an example. Imagine you have a plugin that changes the error message that appears when somebody tries to sign in to your site with the wrong password. In this scenario, the error message is the hook. A plugin could connect to the code that displays that message, and change the text that’s shown.

There are two types of hooks that WordPress understands. They are:

  • Actions: These are used to add or change WordPress functionality.
  • Filters: These are used to alter the functionality of actions.

As you can probably guess, there’s a lot more to how hooks actually work. However, this should give you a rough idea of how the two differ. For now, this is all you’ll need to know, but we recommend that you read up on all the hook types in the Plugin Developer Handbook.

What do you need to know before creating a Plugin?

By now, you may be itching to start creating your own plugin. We’ll get to that momentarily. First, however, you’ll need to ensure that you’re well-prepared.

Basics of creating a WordPress plugin

While it’s not a requirement in order to follow the steps below, some programming or coding experience will be incredibly useful. This is especially true if you want to write your own plugin as opposed to tweaking someonet[t[ else’s code. Having a solid technical foundation will also make it much easier to adhere to WordPress coding standards for developing plugins.

Before you create your plugin, you should also consider how you’ll use names. This applies both to the plugin itself and to the functions it contains. You’ll need to avoid naming collisions, which occur when multiple elements on a site have the same name.

For example, if you name a function in your plugin add_media_page, it will clash with the WordPress function that already uses that string. The best way of avoiding this is to choose a unique prefix, which you’ll apply to every function.

You should also determine how you’ll want to structure the plugin. In practice, this means deciding whether you’ll use a single file for your code or spread it out across multiple files. In addition, you’ll also want to plan out how you’ll structure your plugin’s folders.

Of course, there’s plenty more to consider before you become a full-fledged WordPress developer. For example, plugin security is essential in order to make sure your plugin doesn’t contain any vulnerabilities. You might also want to provide documentation for your plugin if you plan on sharing it.

Google Site Kit plugin

We realize that this is a lot to take in, but don’t worry. A lot of these considerations only become applicable once you create plugins that are intended for others to use, and you’re probably still a little while away from doing that. That’s right — it’s time to develop a plugin!

What you will need?

  • Text editor
  • FTP access to your hosting account
  • A working WordPress installation

To complete the steps in this WordPress plugin tutorial, you’ll need a text editor such as Notepad++ or NetBeans. You’ll also need FTP access to your hosting account and a working WordPress installation.

You can learn how to connect Notepad++ to your FTP server by reading how to connect to FTP with the Notepad++ tutorial. You can also use FTP software like FileZilla to upload your files, and then how to configure the FileZilla client tutorial will teach you how.

This WordPress plugin tutorial is intended for people who already have basic knowledge of PHP. You will write a new function, call existing WordPress functions using parameters, and write PHP comments.

It’s also strongly recommended to create a backup of your website before proceeding further.

How to create WordPress Plugin( in 4 easy steps)

Now you are ready to create your first plugin using a minimal amount of coding. Throughout the following steps, we’ll be creating a plugin that will change the link text that displays when you insert a Read More tag into a post.

Step 1: Set Up a Testing Environment

When you’re developing anything, whether it’s creating a plugin or making other changes that could affect your site, you should always use a testing environment. This is also known as a ‘staging site’ or ‘local environment,’ depending on whether the site is stored on an external server or your own computer.

Regardless of the location, the testing environment should be a private copy of your site. This lets you add to and edit your site’s files and functionality, without the risk of causing damage to the actual live website. This is especially important when you’re working with core files and plugins, as mistakes could cause lasting harm to your site.

Fortunately, setting up a testing site is pretty simple, thanks to the wide variety of tools that are available to help you out. To set up a local environment, we recommend a tool like DesktopServer

Desktop sever application

You can also create an online staging site. This will function as an exact copy of your actual site, except that only you and other admins can access it.

DreamHost

Later on, you can even copy the changes you’ve made on your staging site and import them back to the live version.

When you have your risk-free testing environment ready, it’s time to create the actual plugin.

Step 2: Creating a New Plugin File

To start putting together a new plugin, you will need access to your site’s directory. The easiest way to do this is by using SFTP, which is a method for viewing and managing your site’s files when they’re located on an external server. We’ll be using a client called FileZilla in our example since it’s both free and easy to use.

Startup FileZilla and use the SFTP credentials provided by your web host to access your site. Once you’re in, you’ll need to navigate to the folder that contains your plugins, which is located at /wp-content/plugins/.

FTP connection to access plugins folder in WordPress

To add your new plugin, you’ll need to create a new folder inside this directory. Give it any unique name you’d like. We’ll call our very first plugin.

Creating a new directory for your plugin

This folder is where everything related to your plugin will ‘live’ on your site. Since this plugin is going to be very simple, it only needs to contain a single file, which you’ll create now. This will be a PHP file, which will contain the plugin’s code.

As such, open the new very-first-plugin directory and right-click inside it to select Create a new file.

You’ll be asked to name the file. This should be identical to the folder, so you can call it very-first-plugin.php, Make sure to use the right file extension). This file will now be added to the folder.

Adding file to the directory

Now, you need to add some basic information to the file. That information will be used by WordPress to display the plugin’s name, content, and other information. To do this, right-click on the PHP file and select View/Edit. You will then be asked to open the file, which you can do in any text editor, such as TextEdit or Notepad.

Adding code to the file

The file is empty now so paste the following text into it:




You can even go ahead and Activate your plugin now in the admin panel. Of course, the plugin doesn’t actually do anything yet. That’s because we haven’t added any functionality to it.



Step 3: Adding Code to Plugin



As we mentioned earlier, this plugin is going to change the text that appears when you insert a Read More tag. To see what this looks like normally, create a new blog post and click on the Insert Read More tag icon.



Adding custom code to your Plugin


If you publish the post and check it out on the front end of your site, you will see that the tag has been replaced with a link that says “Continue reading”:



Testing your plugin


This is the text that we want to change. To do that, open up your very-first-plugin.php file again. Then, add a new line at the very end of the file, and paste in the following code:



function dh_modify_read_more_link() {
     return 'Click to Read!';
}
add_filter( 'the_content_more_link', 'dh_modify_read_more_link' );


Let’s quickly break down what this code contains. First, it creates a new function, which we’ve called ‘dh_modify_read_more_link.’ You’ll notice that we added the “dh” prefix, to make sure the name is unique.



All this function does is get the link for the current post, and then apply the anchor text “Click to Read!”. This is the text that will replace “Continue reading.” Of course, you can feel free to change this text to anything you want to use.



The final line in this code uses a filter to hook into a function called the_content_more_link, which represents the Read More link. The filter instructs WordPress to call our new function instead, so the standard link will be replaced with our new version.



At this point, you can save the plugin file. Since you already activated the plugin, its functionality should work right away. Test this by checking your website to see if the link text has changed.



changes in the wordpress page because of the plugin


If it worked, then congratulations! If not, you will need to check your code to make sure you entered everything correctly. In addition, check to see if the plugin is active and that all the function names are correct.



Once you’ve got the plugin to work, you’re ready to progress to the final step.



Step 4: Export and Installation on a Live Site



Your new plugin is now ready to be used on a live site. Fortunately, this step is usually the simplest. All you need to do is to compress the very-first-plugin folder into a ZIP file. If you used a local environment to create your plugin, you just need to right-click on the folder and select Compress.



compressing your plugin directory


If you’ve been using SFTP, on the other hand, you can do the same thing by first right-clicking on the folder and selecting Download.



Downloading your WordPress plugin


Once the folder has been downloaded to your computer, you can compress it just like we mentioned above.



This zip file can then be uploaded to your live site. Open your WordPress admin dashboard, navigate to Plugins, and then click on Add New.



Adding your WordPress plugin to your website


On the next screen, you can select Upload Plugin, which will let you choose a plugin file from your computer.



Upload plugin on WordPress


Select the very-first-plugin.zip file you created and click Install Now. The plugin will now be added to your live site, and you can activate it as usual.



So, that was all. Congratulations on creating your first WordPress plugin added a new link to the admin menu, and displayed a whole new page in the Admin Control Panel! It doesn’t do much just yet, but this is the first step after all. From here, you can build upon what you’ve learned and extend WordPress any way you like. For more tutorials, check out our WordPress tutorials section.

Author avatar
Tim Michaels
I am into WordPress and web development for the last 10 years. I use my experience to help people just starting with WordPress. Follow my blog at WP Uber for everything related to WordPress.
We use cookies to give you the best experience.
Do NOT follow this link or you will be banned from the site!