WebHostingPeople Blog

  • Domains
    • Shared Hosting

  • Cloud VPS
  • Servers
    • Client Area Login

How Can We Help?

Example of writing a simple WordPress Plugin

You are here:

Starting from the moment we initiate a blog on WordPress, we install as many extensions as possible to maximize the potential of the WordPress platform. For those who are not skilled in coding, a single line of code may seem like an insurmountable challenge, but that is not the case. You can create your own personalized WordPress extension. Even though I am not an expert coder, I can demonstrate how you can develop a simple WordPress extension. It’s that simple.

  • Extension Name – When selecting a name for your extension, make sure it is not identical to any existing extension. You can perform this initial step by going to your dashboard and entering the desired name to check if there are any extensions with the same name. In this case, I will name the extension “Notifier”. A quick search reveals that there are no existing extensions with that name. Wow! I am fortunate.

Example Of Writing A Simple Wordpress Plugin

  • Version – You may have noticed that some extensions have frequent updates with a three-digit version number like 2.0.1. In this case, since we are creating a simple one, a two-digit version would be sufficient, something like 1.0.
  • Description – If you intend to create extensions for public use, then this step is crucial. In simple terms, you need to explain what your extension does.
  • Author – The name of the creator.
  • Author URI – Your website URL.
  • Extension URI – In this case, I would leave it empty. This field indicates the dedicated page or support page for your extension.
  • License – For WordPress extensions, a GPL V2 license would be sufficient.
  • License URL- You can link to the page with the information on the license.

Create a .txt file and name it yourname-plugin.txt

Here is the code:

<?php

/* Extension Name: Notifier

Version: 1.0

Description: It displays a notification on your WordPress dashboard

Author: George Mathew

Author URI: http://URI_of_plugin_author_website

Extension URI: clean License: typically GPLv2

License URL:http://gnu.org/licenses

*/

function display_admin_notice()

echo ‘<p>This extension is by Servlet</p>’;

add_action(‘admin_notices’, ‘display_admin_notice’);

?>

Step 1: Access your hosting account and select the WordPress website where you want to create a new extension. In the website’s file structure, you will find a folder named plugins under wp-content. Simply click on that. On the right side, you will see the list of active extensions.

In this case, I am using a test website.

1588176061 860 Example Of Writing A Simple Wordpress Plugin

Step 2- Select new file from the top header

1588176062 419 Example Of Writing A Simple Wordpress Plugin

Step 3: Name it as Yournameplugin.php or anything else you want with the php extension.

1588176063 151 Example Of Writing A Simple Wordpress Plugin

Step 4: A new file will open up. Copy the code from the notepad file and paste it here. The functions should be added just above the ?>.

1588176063 366 Example Of Writing A Simple Wordpress Plugin

Step 4: Go to the WordPress dashboard and navigate to the plugin directory, and you will see a new extension.

1588176067 784 Example Of Writing A Simple Wordpress Plugin

Step 5: You can always edit the extension from the Edit option displayed there.

1588176068 538 Example Of Writing A Simple Wordpress Plugin

Step 6: For now, let’s just activate the extension

1588176072 423 Example Of Writing A Simple Wordpress Plugin

As you can see, the extension is activated, and you will see a notification saying, “See, you have a notification on your dashboard.” You can change it to anything you like.

You may have noticed some functions in the code. Let’s see what they do.

What does add_action do?

Add_action performs the desired action specified by the user. You may not realize this, but many of the common actions on a WordPress blog make use of Add_action.

Here are some common examples:

  • publish_post – called when a post is published or when the status is changed to “published”
  • save_post – called when a post/page is created from scratch or updated
  • trackback_post – called whenever a new trackback is added to a post

What does display_admin_notice do?

It simply displays a message. In our case, it’s the notification.

So, we just created our first WordPress extension. Was it that difficult?

Post Your Comment