+91 88 00 563434 sales@webhostingpeople.net

Our Knowledge Base Articles

Company Blog

Example of writing a simple WordPress Plugin

You are here:

From the second we begin running a blog on WordPress we set up as many plugins as potential to get the perfect out of the WordPress platform. For the non coder a single line of code appears an insurmountable mountain however it’s not the case. You can also make your very personal WordPress plugin.  Despite the fact that I’m no huge coder I can present you how you can create a easy WordPress plugin. It’s that easy.

  • Plugin Identify – If you title your plugin be certain that it’s not an identical to another plugin on the market. You may carry out this primary step by simply heading over to your dashboard and keying within the desired title to see if there exists any plugin with that title. Right here I’m going to call the Plugin “Notifier”. A fast search reveals that there isn’t any plugin with that title. Wow! I’m fortunate.

Example Of Writing A Simple Wordpress Plugin

  • Model – You may need seen plugins with frequent updates with the three digit model like 2.0.1. On this case since we’re going for a easy one, a two digit model would suffice one thing like 1.0
  • Description – When you plan to make plugins for public use then this step is essential. In easy phrases you want to clarify what your plugin does.
  • Creator – The title of the creator
  • Creator URI – Your web site url.
  • Plugin URI – On this case I would go away it empty. This area signifies the devoted web page or help web page on your plugin.
  • License – For WordPress plugins a GPL V2 license could be sufficient
  • License url- You may hyperlink to the web page with the knowledge on license

Create a .txt file with and title it as yourname-plugin.txt

Right here is the code:


/* Plugin Identify: Notifier

Model: 1.0

Description: It shows a discover in your WordPress dashboard

Creator: George Mathew

Creator URI: http://URI_of_plugin_author_website

Plugin URI: clean License: often GPLv2

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


perform display_admin_notice()

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

add_action(‘admin_notices’, ‘display_admin_notice’);


Step 1: Go to your internet hosting account and choose the WordPress web site the place you wish to create a brand new plugin. Within the web site’s file construction you can see a folder below wp-content with the title plugins. Simply click on on that. On the fitting facet you will notice the listing of energetic plugins.

On this case I’m utilizing a take a look at web site.

1588176061 860 Example Of Writing A Simple Wordpress Plugin

Step 2- Choose new file from the highest header

1588176062 419 Example Of Writing A Simple Wordpress Plugin

Step 3: Identify it as Yournameplugin.php or the rest you need with the php extension.

1588176063 151 Example Of Writing A Simple Wordpress Plugin


Step 4: A brand new file opens up. Copy the code from the notepad file and paste it in right here. The features must be added simply above the ?>.

1588176063 366 Example Of Writing A Simple Wordpress Plugin

Step 4: Go to the WordPress dashboard and go the the plugin listing and you will notice a brand new plugin.

1588176067 784 Example Of Writing A Simple Wordpress Plugin

Step 5: You may at all times edit the plugin from the Edit possibility displayed there.

1588176068 538 Example Of Writing A Simple Wordpress Plugin

Step 6: For the second let’s simply activate the plugin

1588176072 423 Example Of Writing A Simple Wordpress Plugin

As you’ll be able to see the plugin is activated and you’ll see a discover “See you could have a discover in your dashboard.” You may change it with something that you simply like.

You may need seen some features within the code. Let’s see what they do.

What does add_action do?

Add_action does the magic to our code. Add_action is the wordpress perform that really helps carry out the motion specified by the person. Chances are you’ll not understand this however many of the widespread actions on a WordPress weblog make use of Add_action

Listed below are some widespread examples

  • publish_post – referred to as when a submit is printed or when standing is modified into “printed”
  • save_post – referred to as when a submit/web page is created from begin or up to date
  • trackback_post – referred to as at any time when a brand new trackback is added right into a submit

What does display_admin_notice do?

It simply shows a message. In our case it’s the discover.

So, we simply made our first WordPress plugin. Was it that onerous?

Leave a Comment