WordPress Managed Hosting - 40% Off For 4 Months - Coupon Code: BFCM2020 Avail Now

How To Create A WordPress Plugin

Moeez — April 26, 2017 4 Minutes Read

Here is how WordPress Codex defines WordPress Plugin:

A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress Plugin Application Program Interface (API).

This article will take you through a WordPress plugin development guide. I hope that by the end of this guide, you will be able to create a WordPress plugin.

Starting a Plugin File

The first step in creating a WordPress plugin is starting a plugin file. A plugin must contain a file with meta information which tells WordPress what it is and how to handle the plugin within your website. Plugins can be installed, deleted, activated, and inactivated.

Open  the folder wp-content/plugins/wpblog/ and create a new file inside it called wpblog-reviews.php

The path to the file should now be wp-content/plugins/wpblog/wpblog-reviews.php. The information should be formatted as follows:

/**

* Plugin Name: Custom WP Blog Reviews

* Description: This is simple plugin which deal with custom post type.

* Version: 1.0

**/

With this information added, save your file and navigate to your WordPress admin area.

WordPress Plugin

Open the file wpblog-reviews.php. Add the following code to it:

At this point, visit the WordPress admin area. If everything is on track, you will see a new custom post type:

Blog reviews

Below, I will add a new music review.

Add new review

Our code now works. I will now create a page that will use this code:

Finally, I will create the WP Blog Reviews page once the plugin has been activated.

Fetch Content On the FrontEnd

Start by creating a template file template-wpblogreview.php, located in the theme folder. Open the file and add the following code to it:

Now, in the admin area, go to Pages, edit the page WP Blog Reviews and select the template of wpblog, as shown in the screencap below:

Now, view the page. You can see the post of your custom post type.

Conclusion

This is a relatively simple plugin. You can extend it so much further by including several predefined templates. However, remember that creating a plugin is no easy task. You should go through careful planning before even starting the WordPress plugin development process. Proper planning will ensure that the development process goes through without problems and you create a WordPress without many hurdles.

Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.


Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.

Moeez is ‘The’ blogger in charge of WPblog. He loves to interact and learn about WordPress with people in the WordPress community. Outside his work life, Moeez spends time hanging out with his friends, playing Xbox and watching football on the weekends. You can get in touch with him at moeez[at]wpblog.com.

THERE'S MORE TO READ

Newsletter

WordPress Help Zone - Ultimate WordPress Pit-Stop

Learning WordPress? Or are you expert enough to help others? Join our WP Facebook group!

Secured By miniOrange