How to Create your First WordPress PlugIn


Since we are all going to get our hands on wordpress plugin for the first time, it makes perfect sense we should try something simple. So, let start with something elementary wordpress plug-in that will do only a simple basic task – like displaying a text on the top of the WordPress dashboard, whenever a change is being made. Pretty cool huh! So, let start and get our hands dirty with the codes of course.

Lets start with creating a new text file and name it as my-first-plugin.php. Once it is done, just copy and paste the below mentioned code into the file:

<?php
/*
Plugin Name: Test Plugin
Version: 1.0
Description: Just a test plugin!
Author: Michael Evans
Author URI: http://www.mywebsite.com
Plugin URI: http://www.mywebsite_wordpress_plugin.com
License: A slug describing license associated with the plugin (usually GPL2)
*/
?>

This code may look scary but in fact it is a simple and standard plugin information header that lets WordPress indentify that this is a plugin.

Now, the code may appear intimidating at the first look but just go down the details a little and you will find that each of the line in the code is self explanatory. But still, we would love to dig down the detail a few meters, kidding of course, so that a newbie can have a better understanding.

Plugin Name: Simple, as it sounds. Just the fancy name of the plugin you have chosen but make sure that the name is not going to have a headlong collision with an existing plugin. Better safe than cure.

Version: You can put whatever version you would like to put here. However, since we are not going to create a highly complex plugin that will require frequent updates, we will have a great time with simple 2-digit version system (eg. 1.0) rather than  opting for the complex -digit version system (eg. 1.0.0).

Author – I think I do not need to explain this. You are smart enough to guess this.

Author URI – You can place the URL of your website.

Plugin URI – It is common practice among wordpress plugin developers to create a dedicate page for their plugin where general users can have ample information about that plugin. Once you have set up that page, just place the URL here in this place.

License – Do you have any license associated with your plugin, then name it here.

So, every thing has been explained and it is time to upload it to Plugin directory so that WordPress engine can recognize it. You can plugin directory here – wp-content >> Plugins directory. Once it is done, just press the ‘refresh’ plugin option in your admin dashboard.

Now, there you will find three options – Activate, Deactivate and Delete. But since we have not placed any code in it, activation will not have any impact. So, roll up your sleeves because we have some work to finish. Just place this code above ‘?>’ to make it work:

  function display_admin_notice() {
echo '<p>Just filling out the blank space</p>';
}

add_action('admin_notices', 'display_admin_notice');

How to Create your First Wordpress PlugIn

The first line of the code – display_admin_notice() – is created for showing a simple text message. But it is the second line of the code that makes the real difference. add_action() function is a general WordPress function that is strictly related to an action initiated by an user. Action has a special meaning in WordPress. It means an event that is initiated by WordPress engine whenever an event occurs like a new plugin gets installed or some changes being made to the theme.

So, time is up to install this plugin. And once it gets installed, you will receive a notification on the top admin dashboard that may be something like this – yup, we have created our first ever WordPress plugin.

How to Create your First Wordpress PlugIn

Join Our Email Newsletter

Like what you read here in this blog post? Get free blog updates in your Email!

When signing up you will initially receive a confirmation email requiring your approval to complete the Subscribtion.

Start learning on Udemy today!

Comments

  1. says

    Hello are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and create my own. Do you require any html coding expertise to make your own blog? Any help would be greatly appreciated!

  2. says

    I have been exploring for a little for any high-quality articles or blog posts in this sort of area . Exploring in Yahoo I finally stumbled upon this site. Reading this information So i am glad to exhibit that I’ve an incredibly excellent uncanny feeling I came upon exactly what I needed. I so much no doubt will make sure to don?t fail to remember this web site and provides it a look on a constant basis.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>