How to Create Simple WordPress Plugin

By | October 16, 2013
17-03-30

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?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
*/

?>

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”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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>

 

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 *