Tutorial: How to Create Wordpress Plugins

by Aky Joe on January 1, 2010


Wordpress is the most robust platform, for the Blogging as well as for Content Management System Websites. Wordpress allows you to code and extend its capabilities using you own innovations.

In this tutorial, I’ll show you how to write a basic Wordpress Plugin. Coding a wordpress plugin, should have a basic php knowledge, the functions, the operators, the statements, etc…

Before I begin coding the Basic Wordpress plugin, I want to share some key points to kept in mind during your development.

  • Choose a unique and name with relevance to its functionality, for your plugin.
  • Indentation and Comments should be always used, so as to ease the understanding of the Plugin Coding.
  • Test your plugin on Wamp servers, that is on localhost, with latest version of wordpress.

Basic Content

Wordpress plugin consists of two basic files, one is the main php script file, and other optional but important, readme.txt file. These files can be either archived in a folder and can be placed under the WP-Content>WP-Plugin Directory.

image thumb Tutorial: How to Create Wordpress Plugins

Plugin Information

Open the my-first.php with the notepad or any php editor, like I use EnginSite Editor for PHP. Code the below mentions lines, which stores the information about the Plugin.

image thumb1 Tutorial: How to Create Wordpress Plugins

Code:

<?php
/*
Plugin Name: My-First
Plugin URI:
http://wordpress.org/#
Description: This is the most basic wordpress plugin, gets input from the user and displays it on every page.
Author: AkyJoe
Version: 1.0
Author URI:
http://www.themepremium.com/
*/
?>

Save the php file and login to the Wordpress Dashboard > Plugins, you will find this the plugin listed, and waiting for the activation.

image thumb2 Tutorial: How to Create Wordpress Plugins

Plugin Working

At this, point we have achieved our goal to list the Plugin under Plugin Directory of the Wordpress Admin. Before activating the Plugin, we must code, the main objective of the Plugin. The working of the Plugin. Below is a simple function made to echo a string text, when we activate this plugin.

function my_first()
{
echo “My First Wordpress Plugin Works Fine.”;
}

image thumb3 Tutorial: How to Create Wordpress Plugins

Testing Plugin

In order to test the working of My-First Plugin, we will have to add a function call code in Single.php, Index.php or  it can be Header.php. For instance, I added the code in the Single.php

Code

<?php if(function_ exists(‘my_first’)) { my_first(); } ?>

image thumb4 Tutorial: How to Create Wordpress Plugins

Now testing the above code on the Single Post Page of the Wordpress Blog. The below screen shot says everything.

image thumb5 Tutorial: How to Create Wordpress Plugins

This ends our basic tutorial for Wordpress Plugin Development. For any queries or any other assistance, post comments as your feedbacks.

Related posts:

  1. Tutorial 2: How to Create Wordpress Plugin Admin Panel
  2. Tutorial 3: How to create a Wordpress Sidebar Widget using Plugin ?
  3. Wordpress Random Posts With Custom Code
  4. Split Test Your Wordpress Theme for better CTR and Performance
  5. How To Highlight Author Comments In Wordpress

Wpfreelancer

{ 1 trackback }

CoreBloggers
January 4, 2010 at 6:05 pm

{ 2 comments… read them below or add one }

Tom | Build That List January 11, 2010 at 6:14 am

I always wondered how hard it was to create a plugin. I guess the hard part is coming up with something original and then coding that.

Reply

Rohit Sane January 19, 2010 at 9:09 pm

This is okay! Just printing something is okay!

But can you give us some fair idea about how other plugins are created, not just printing. I know different ideas are executed differently!

Reply

Leave a Comment

Connect with Facebook

Previous post:

Next post:

.