Tutorial: How to Create WordPress Plugins

by Aky Joe on January 1, 2010

WooThemes - Made by Designers

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

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

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

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

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

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

image

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. How To Highlight Author Comments In WordPress
  5. WordPress Problem wp-includes/pluggable.php on line 865 [Solved]

Wpfreelancer

{ 3 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

WebVeins July 23, 2010 at 6:08 pm

Its so simple…
Where is the tutorial for advanced plugins with database interaction.
Thanks

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post:

.