A few days earlier I had written a Post showing you how to write some php code to create a function that will display Woo Commerce product Reviews Anywhere on your page using a Shortcode. I had also mentioned in that blog post that I will create a plugin for that. I thought this is perfect opportunity to show you How To Create Your Own WordPress Plugin. This will require some knowledge of WordPress API and PHP and I am assuming that you already understand what a plugin is.

Why is plugin preffered over modifying functions.php?

The real question is, why should you create a plugin? You could have achieved the same functionality by writing the function in functions.php and then using it.

Writing a Plugin gives you a portable Software Component, a library, that is available for you to re-use and you can also publish it in the WordPress Repository for other community to benefit from.

How To Create Your Own WordPress Plugin?

The first step is to create a folder a.k.a Directory. I name the directory the same as my plugin. For this example I will call my directory “HelloPlugin”. The second step is to create an empty php file and copy it inside of the directory you just created in step 1. I will call my file HelloPlugin.php. So the first 2 steps were really smooth.
Next, you will need to edit the PHP file and specify the plugin meta data at the top of the file:

You will need to follow the semantics described for WordPress Plugin writing. The fields inside of the snippet below are pretty self explanatory. Plugin Name is the name of the plugin, Plugin URI is the URL of that will be hyperlinked for plugin support, Description describes what the purpose of the plugin is. Version will describe the Version of the Plugin. Author specifies who created the plugin and the License specifies what kind of license the plugin will be released under. This is fairly standard

Plugin URI: idesignsmart.com Description: This plugin will enable putting your product reviews on any page/post or other products using a shortcode.
Version: 1.0
Author: Asad Siddiqi
Author URI: http://twitter.com/hiasad
License: GPLv2+
Text Domain: wp_wc_reviews_anywhere

At this point if you save your file and trying uploading it as a plugin it should work. So for all practical purposes I just showed you How to Create Your Own WordPress Plugin. Now lets create a function that my plugin will use:

I want to add a shortcode that will output the markup needed to achieve my functionality so I will let my plugin handle that.

add_shortcode('SayHello', 'output_hello');
function output_hello()
echo("Hello WP Plugins");

At this point if your plugin is installed in the system you should be able to use your shortcode in square brackets [SayHello] and should see your output. Fun and Enjoy.

IDesignSmart is a premium WordPress Services Provider. We offer beautiful responsive websites at an affordable rate. At IDesignSmart we have leading WordPress developers and we enjoy creating Custom Page Templates and Plugins. We offer full customizations of premium themes using the proper documented way.