How To Create A Custom WordPress Plugin Step by Step With Example

Creating a custom WordPress plugin is a subject for [WordPress]( developers. We will start from the basics of plugin development step by step with an example.

These handy tools let you add all kinds of features to your site in seconds. 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.

Plugins add extra functionality to your WordPress site over and above what comes with WordPress core. Everything from a booking calendar or animated slider, to a full-featured learning management system or online marketplace — you can add them all to your site with plugins.

## How To Create Custom WordPress Plugin

Writing your own WordPress plugin is not that difficult if you are a web developer with basic [PHP skills](

A plugin is a simple program, a set of functions, that adds a specific set of features and services that can execute in different sections of your WordPress site.

## What is WordPress Plugin?

A **WordPress plugin** is a standalone set of code that enhances and extends the functionality of WordPress. By using any combination of PHP, HTML, CSS, JavaScript/jQuery, or any other web programming language, a plugin can add new features to any part of your website, including the Admin Control Panel.

You can modify the default behavior of WordPress, or remove unwanted behavior completely. Plugins allow you to easily customize and personalize WordPress to fit your needs.

## The Basics of a WordPress Plugin

Plugins are external features that you can add to your WordPress website to increase the functionality of your site. The programming language of WP plugins is PHP and WP uses the MySQL database. If you want to create a plugin with integration with the database, you should know MySQL.

## Types of Custom WordPress Plugin

Plugins can carry out lots of tasks. What they all have in common is that they add extra functionality to your site. Types of WordPress plugins include:

* **site maintenance plugins**: for things like security, performance, or backups
* **marketing and sales plugins:** for things like SEO, social media, or eCommerce
* **content plugins**: custom post types, widgets, Shortcodes and etc.
* **API plugins**: that work with the WordPress REST API or pull in external content from services like Google Maps
* **community plugins:** that add social networking features

## The Basics of a WordPress Plugin Development

You can create your custom WordPress plugin in three steps.

* Create a folder and name it to your desired name for your plugin
* Create a PHP file inside the folder and name it whatever you want
* Insert the below code into the PHP file


/** * Plugin Name: YOUR PLUGIN NAME */

* Zip the folder to .zip format
* Install the plugin using the [WordPress admin plugin upload](

## How to Create a Custom WordPress Plugin?

### 1. Prepare Basics

Before starting coding, it is helpful to understand [best practices]( for plugins so your code can be high quality right from the start. 

To develop a custom WordPress plugin go to **/wp-content/plugins/** of your site.

Create a folder and name it **hs-example**.

Go to the hs-example and create an **example.php** file.

Open the example.php file.

Add the below code to the PHP file.

<?php /** * Plugin Name: Example */

WordPress will detect your plugin by the above code. If you go to **Plugins** in your admin panel, your plugin will be there.

Activate it. you can see there is just a name without other information about the plugin. To add more information edit the code like below.

<?php /** * Plugin Name: Example * Plugin URI: * Description: Example is a simple plugin. * Version: 1.0.0 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Honar Systems * Author URI: * License: GPL v2 or later * License URI: * Text Domain: hs-example * Domain Path: /hs-example */

If you go to plugins in the admin panel you will see the changes.

Read the descriptions of the items and add or remove them based on your desire.

#### 1.1. Items we can define in Plugin Main File

* **Plugin Name:** (*required*) The name of your plugin.
* **Plugin URI:** The home page of the plugin, should be a unique URL, preferably on your own website. This *must be unique* to your plugin. You cannot use a URL here.
* **Description:** A short description of the plugin, as displayed in the Plugins section in the WordPress Admin. This description should be fewer than 140 characters.
* **Version:** The current version number of the plugin.
* **Requires at least:** The lowest WordPress version that the plugin will work on.
* **Requires PHP:** The minimum required PHP version.
* **Author:** The name of the plugin author.
* **Author URI:** The author’s website or profile on another website.
* **License:** The short name (slug) of the plugin’s license (e.g. GPLv2).
* **License URI:** A link to the full text of the license.
* **Text Domain:** The text domain of the plugin.
* **Domain Path:** The domain path lets WordPress know where to find the translations.
* **Network:** Whether the plugin can only be activated network-wide. Can only be set to *true*, and should be left out when not needed.

The below example allows file-level PHPDoc DocBlock.

/** * Plugin Name * * @package PluginPackage * @author Your Name * @copyright 2019 Your Name or Company Name * @license GPL-2.0-or-later * * @wordpress-plugin * Plugin Name: Plugin Name * Plugin URI: * Description: Description of the plugin. * Version: 1.0.0 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Your Name * Author URI: * Text Domain: plugin-slug * License: GPL v2 or later * License URI: */

### 2. Development of Custom WordPress Plugin

Now your plugin is ready for programming. You can add your PHP codes after the introductions comment.

We are going to change the “**Read More**” text of the post in our plugin.

/** * Plugin Name: Example * Plugin URI: * Description: Example is a simple plugin. * Version: 1.0.0 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Honar Systems * Author URI: * License: GPL v2 or later * License URI: * Text Domain: hs-example * Domain Path: /languages */ function hs_modify_read_more_link() { return ‘<a class=”more-link” href=”‘ . get_permalink() . ‘”>Click to Read!</a>’; } add_filter( ‘the_content_more_link’, ‘hs_modify_read_more_link’ );

The above code will change


More details and examples: [](


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Your Advertisement Here