How to create WordPress Plugins

WordPress comes with one of the most fascinating features of having multiple plugins available in it which makes the task of adding the new functionality to the existing core features of WordPress by simply adding on the new plugin. But there might occur some scenarios where the functionality that you are searching for may not be available in the available plugins of WordPress or you want to write your own feature functionality. In all these cases, you can go for adding your very own plugin with a minimal number of lines of code and with very few clicks.

The below steps will lead you to make your own WordPress plugin

Step 1 – Prepare the environment where you will test your plugin

Before you go for making any kind of change for your website, you need to make sure that you switch to a testing environment which is also sometimes referred to as a local environment or staging site on the basis of where your site resides is whether locally or on the external device. Irrespective of wherever you get a copy of your site to work on it should be solely for private use and modification which makes sure that you can add, remove and edit the functionality without fear of affecting any existing functionality that is live on the platform.

There is a wide range of tools available out there which make the setting up of the local environment quite easy. One of the most widely used tools for this purpose is DesktopServer which makes it easy for you to get the local version installed on your machine of WordPress on your system. You can find a way to download and install a desktop server on this link. Once, you have got this environment where you can play around and create your own plugin and functionalities, you will be ready to create your own plugin.


Step 2 – Create a new file for the plugin

In order to get access to the directory of your site you can make use of SFTP which can be used when the site is located externally and it helps in managing and observing the files of the site. Another client that can be used for the same purpose is FileZilla which is quite easy to use. Both the platforms are available free of cost. You can download FileZilla from this link.
You can start using FileZilla by entering the credentials of SFTP as provided by the host of the website. Then move to the folder named wp-content which will contain inside it a folder called plugins as shown in the below image –

now create a new directory named bitarray_sample_plugin inside plugins directory as shown below –



We will try to create a simple plugin that contains all its code in one single php file. The directory that you have created inside the plugins folder will contain everything related to the plugin that you want to add. Create a new file named samplePlugin.php inside the bitarray_sample_plugin folder as shown in the below image –


For now, we will roughly add some comments in this empty file describing the information about the plugin as shown below –



Right now, my directory is in the local environment on my system. If your copy of the site is located externally, it will pop out saying do you want the upload the file back to the server where you can go for clicking on yes. After this, the plugin will be visible on the dashboard of the admin



Step 3 Add code to the plugin file

Now, we will add a new post and then add the Read More tag to it by simply clicking on that icon as shown below:



Once the post is published and visible on the site on its front end, the tag that we added can be seen converted into a link saying “Continue reading” as shown below –

Now, it’s time to do certain modifications in our php file that we created for the plugin to code We will add the following code containing a function that will allow modifying the existing read more link. The contents of the file will be replaced and the following code will be added to it as shown in the below image




What we have done here is create a unique named function that will convert the text on the link of continue reading to “Click to Read!”. The current post is treated as the source from where the link and its content is retrieved by the function. Further, the function appends the new text to the link with a click to read as content that replaces the older content. We can give any name and text we want to this particular link. This results in WordPress replacing the older link that was standard with our newer changes in it. Now, you can save the samplePlugin.php file or whichever you have created and test the working on the site. We get the following output on-site which means that the changes were done successfully and our plugin is working fine on the site –

In case something goes wrong and you are not able to see the expected output on your site. Don’t panic. Give a check on the code of our plugin php file and make sure everything is written correctly. Also verify that the names of functions, as well as the active status of the plugin, is set properly. Once your plugin works properly in the local environment, it’s time to export it on the live website.



Step 4 – Installation of the plugin on the live platform where the website is on by exporting it

Now, it is the last step that we need to follow for your plugin to work properly on the live website where your site is running. What we need to do is firstly, compress the folder of bitarray_sample_plugin and convert it into a zip file. What we need to do is simply right click on the folder if you are using the local environment and then choose the option of compress as shown in the below image –




In case you are using SFTP the folder can be simply compressed and downloaded on the local directory by simply opening the folder in SFTP and then right-clicking the folder named bitarray_sample_plugin and then from the available options in the drop-down choose the option of “download” which then results in downloading the folder. The options will be as shown below –


Once the folder is downloaded, you can simply compress the same by simply following the guidelines mentioned priorly which is right-clicking the downloaded folder and then choosing the option of compress from the drop-down.

Once your zipped folder is ready, you can proceed with uploading the same on the website which is running live. The steps required to follow include opening the dashboard of admin on WordPress and then clicking on the plugins option available on the left side of the dashboard as shown in the below image –


Further clicking on that will give you the option of Add New option as shown below –


You can select the bitarray_sampl_plugin over here and then after clicking on Apply button, you can observe that the new page contains the provision of choosing and uploading the plugin that you created. You can simply select the file of your plugin from your local computer service and upload it. The page will look as shown below –



You need to click on the option of choose file which will open up the contents on your device where you can browse the zip file that you have created named and further give a click on Install Now button just below choose file button. This will make the addition of your newly created plugin on the live website and you can simply activate it by going to plugins and then searching for your plugin in the search box and then click on activate option.

So, there you go! After following all the above steps, you will successfully be able to create and upload your very own plugin on the live website present on WordPress.

In short, the steps required to create and publish your own plugin include setting up the local environment containing a copy of your website contents, files, and directories so that you can manipulate and change it for testing purposes, then create a new file for your plugin in the newly created folder of plugins, write the sample code and the functionality of your plugin in this php file and finally exporting the plugin on the live website and installing and activating the same so that it works properly.

+ There are no comments

Add yours