Categories
WordPress

How to Create a WordPress Plugin – Hello World!

A wordpress plugin can do wonderful things with your blog. Developing a wordpress plugin may look more difficult compared to themes but if you know PHP then thanks to the hooks and functions, developing a wordpress plugin is very simple.

This is a very simple and basic tutorial in which we will create a simple plugin that prints Hello World! on your blog.

Let us begin with creating a new folder inside the wp-content/plugins/ directory. I will name is as hello-world.

Create a new php file inside the folder we just created. I am naming this file as hello-world.php. Now Before we get started with the plugin, let us first add the meta data to the plugin. Open the hello-world.php and add some information on top, something like this

<?php
/*
Plugin Name: Hello World
Plugin URI: http://www.yourdomain.ca
Description: A simple Hello Word Plugin
Version: 1
Author: John Doe
Author URI: http://www.yourdomain.ca
*/

That was our meta data. Meta data is pulled out by the wordpress core and is displayed in the plugins page of your wordpress admin. Now we will create a simple php function to print Hello World! Add this code below to create a simple hello world function

function helloworld() {
        echo ("Hello World!");
}
?>

Save the file. The above code will output Hello World! when the function is called from any of your pages. Go to the Manage Plugins page (wp-admin/plugins.php) and activate the Hello World Plugin.

Now we need to call the function from some file to execute it. Open the index.php (or any file like footer.php) file in your current theme folder and add this anywhere where you would like to see the code. (preferably at the end near the footer).

<?php
if(function_exists(’helloworld’)) {
helloworld();
}
?>

Save the file and reload your blogs main page. You mush be seeing Hello World! somewhere where you have put the code. This example might not be interesting but it is a good start to learn coding plugins.

Make sure you are subscribed to feeds, as more tutorials will be coming soon.

Related posts:

  1. WordPress Plugin – RSS Post Editor
  2. How to make your WordPress Theme Widget Ready
  3. How to Create Post Accordions in WordPress
  4. WordPress Plugin – Techytube
  5. 3 Most Important SEO Plugins for your WordPress Blog