Create wordpress custom plugin from scratch

In this post, I am going to explain how to create custom WordPress plugin from scratch, But before start coding need to know what is a plugin and why use plugins in WordPress.

What is a Plugin

Plugin is a program/script or set of functions written in the php scripting language that add set of specific features or functionality in WordPress. Using WordPress plugins customize WordPress default functionality and create functionality.

There are two ways two create plugins first create fresh independent plugin and second dependent plugins which is known as plugins Addons. Word-press plugin development is not hard process if you have knowledge of WordPress hooks and functions.

Creating wordpress plugin

When you need to create well structured plugin then need to follow below some important instructions.



=>The first task in creating a WordPress Plugin is to think about what the Plugin will do, then choose a unique name for your Plugin like remove woocommerce related products.

=>Then create a folder in plugin folder with your plugin name for example remove-related-products

=> Then create main file in your plugin folder with a name derived from your chosen Plugin name for example remove-related-products.php, Your plugin file name should also be unique so that your plugin not conflict with other plugins. A good solution for unique you can use your name in plugin prefix like webprep-remove-related-products.

=> If you want to host your Plugin on https://wordpress.org/plugins/, you need to create a readme.txt file within your plugin directory in a standardized format. See https://wordpress.org/plugins/about/readme.txt for a description of the format or use the automatic plugin ‘readme.txt’ generator.

In this post will describe plugin development with example of my simple wordpress plugin which already hosted on wordpress.org , This plugin is a woocommerce addon which is created for remove related products from products page, you can download that plugin from my wordpress.org profile https://wordpress.org/plugins/remove-related-products/

This plugin is created for product template, when activate plugin then automatically removed related products from product page.

In plugin main file need to add some commented code like Plugin name,author, author URI and version etc. These details necessary for plugin development you can copy below code and paste it in your plugin main file.

Now you can start plugin code and write required code and functions. If you want to create plugin with any MVC framework structure then you can do it.

Full example of plugin

In this article, I have added full code of my simple wordpress plugin you can copy below code or download from here

 

5 Comments

Add a Comment

Your email address will not be published. Required fields are marked *