How to Create Simple WordPress Plugin

By | October 16, 2013
24-04-19

Creating a WordPress Plugin is a little bit easier. Here is the simple tutorial for wordpress plugin development. Plugin development involves following important aspects

 

Create-Simple-WordPress-Plugin-cover-image

Create-Simple-WordPress-Plugin-cover-image

 

This plugin will display today’s date

How to Use this Plugin
  1. Download this plugin and install in your server/localhost
  2. Posts -> Add New
  3. type   in your post

You will see today’s date with style

 

Header

[code type=php]
<?php
/**
* Plugin Name: Name Of The Plugin
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin’s Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A “Slug” license name e.g. GPL2
*/

?>
[/code]

This header values will be replicated in plugin page

wordpress-plugin-description

wordpress-plugin-description

 

Plugin Code (freeze-plugin.php)
  • freeze_plugin() – this php function will return today date with CSS style given below.
  • add_shortcode(‘freeze’, ‘freeze_plugin’) – creates shortcode “freeze”

[code type=php]

<?php
/*
Plugin Name: Freeze Plugin
Plugin URI: http://freezecoders.com/
Description: Freeze coders is a simple plugin with short code to display current date.
Author: prasad
Author URI: http://freezecoders.com/
Version: 1.0
*/
function freeze_plugin()
{
echo “<div class=’freeze-date’>”.date(‘M d, Y’).”</div>”;
}

add_shortcode(‘freeze’, ‘freeze_plugin’);

?>

<style type=”text/css”>
.freeze-date
{
background: #ccc;
padding: 5px 15px;
font-size: 24px;
}
</style>

[/code]

 

How to Create ShortCode

Shortcode in wordpress is like a abbreviation, which is used to call a function. Main use of shortcode is, inside post we can’t call php function and shortcode will do intermediate.

add_shortcode(‘freeze’, ‘freeze_plugin’);

freeze – shortcode name, it will be used as freeze

freeze_plugin –  freeze shortcode’s equivalent  php function

 

Compressed Format

Folder name: Freeze-Plugin
File name: freeze-plugin.php

freeze-plugin.php file should be inside the folder Freeze-Plugin

Make the folder as .ZIP format

Create-Simple-WordPress-Plugin

Create-Simple-WordPress-Plugin

Then you can use this plugin in wordpress by installing and activate.

Leave a Reply

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