How to create a plugin ?

Introduction

A WordPress Plugin is a program or a set of one or more functions written in the PHP scripting language, which adds a specific set of features or services to the WordPress site. A WordPress plugin allow users to use easily, modify, customize, and enhance any WordPress website. Instead of changing the core software WordPress is built on you can rather create a plugin to extend it. A WordPress Plugin can be seamlessly integrated with the site using access points and methods provided by the WordPress Plugin Application Program Interface (API).
Creating a plugin of your own is really not that difficult and can solve a lot of problems. This blog you can learn how to create a WordPress plugin.

Creating a WordPress Plugin

For beginner wordpress developer it’s not difficult to create a plugin. When creating a WordPress plugin there are some standards to uphold to when doing so. Below some key points to remember when creating your own plugin.

Plugin Name
The first task in creating a WordPress Plugin is to think about what the Plugin will do, then choose a (preferably unique) name for your Plugin. If you’re planning on making a plugin that doesn’t exist yet you will need to first determine its name. To be extra sure you will want to do a search in the WordPress Plugin repository. Some developers choose a name that describes more of what the plugin does so the end user can establish a quick connection with the name. The name itself can be multiple words.

Plugin Files
The next thing you need to do is create a folder to store your plugin. Go to the wp-content/plugins/ directory in your WordPress installation and create a folder called wp-best-faq. Keep in mind that whatever you name your plugin’s folder will be your plugin’s slug. So if your plugin was named my-plugin-name then your PHP file name would most likely be my-plugin-name.php. Using a unique name is crucial so no two plugins use the same name.

You can also choose to split your plugin into multiple files; similar to the way WordPress is built. Assets such as images, CSS, and JavaScript are common to see within installed plugins.

Readme File
Readme file used for giving all information about plugin. Usually these files give a quick description of the plugin as well as sometimes offer change logs which indicate previous updates and maintenance announcements to users. For more information please see WordPress sample readme.txt

Creating Standard Plugin File
As you know our plugin folder name is wp-best-faq  than our file name wp-best-faq.php. Open the wp-best-faq.php file in a text editor, and paste the following information in it:

<?php
   /*
   Plugin Name: WP Best FAQ
   Plugin URI: http://wp-best-faq.com
   Description: a plugin to create for display FAQ
   Version: 1.2
   Author: Mr. Demo
   Author URI: http://demo.com
   License: GPL2
   */
?>

The minimum WordPress needs to establish your file as a plugin is the line.
Plugin Name: WP Best FAQ
Always remeber plugin name should be unique. The rest of the information will be displayed within the Admin area under the  plugins section.

Creating a custom post type
Add the code below:

<?php
// Register the Custom FAQ Post Type
function register_faq_cuatom_post() {
 
    $labels = array(
      'name' => __('FAQ', 'best-faq'),
      'singular_name' => __('FAQ', 'best-faq'),
      'add_new' => __('Add New', 'best-faq'),
      'add_new_item' => __('Add New Question', 'best-faq'),
      'edit' => __('Edit', 'best-faq'),
      'edit_item' => __('Edit Question', 'best-faq'),
      'new_item' => __('New Question', 'best-faq'),
      'view' => __('View FAQ', 'best-faq'),
     'view_item' => __('View Question', 'best-faq'),
     'search_items' => __('Search FAQ', 'best-faq'),
     'not_found' => __('No FAQs found', 'best-faq'),
     'not_found_in_trash' => __('No FAQs found in Trash', 'best-faq')
    );
 
    $args = array(
        'labels' => $labels,
         'public' => true,
         'query_var' => true,
         'menu_position' => 20,
         'menu_icon' => 'dashicons-editor-help',
        'has_archive' => false,
        'supports' => array('title', 'editor', 'revisions', 'page-attributes'),
        'rewrite' => array('with_front' => false)
    );
 
    register_post_type( 'faq', $args );
}
 
add_action( 'init', 'register_faq_cuatom_post' );  ?>

And finally we need to create functions adding the code below for activate and deactivate the plugin.

<?php
// // Activates function if plugin is activated
 function wpb_install()
{
...
}
register_activation_hook( __FILE__, 'wpb_install');
// // Deactivate function if plugin is deactivated

 function wpb_uninstall()
{
...
}
register_deactivation_hook( __FILE__, 'wpb_uninstall');
 ?>

Now you can see below image after activated plugin you have created custom post type FAQ.

In this blogs we have created simple plugin. If you know about some basic information about WordPress you can create own plugin.
If you have any queries please let me know I’ll give you better informations.

Thank you 🙂

 

 

2 thoughts on “How to create a plugin ?

Add yours

  1. Hey fantastic blog! Does running a blog such as this take a large amount of work?
    I’ve absolutely no knowledge of programming but I had been hoping
    to start my own blog in the near future. Anyways, should you have
    any ideas or techniques for new blog owners please share.
    I understand this is off subject however I simply wanted to ask.
    Many thanks!

    Liked by 1 person

    1. Thanks,

      I am freelance WordPress developer. I have total 6 years experience in development & designing in many types of PHP frameworks. If you want to give any work in future please let me know.
      Thanks you 🙂
      Pradeep Chaturvedi

      Like

Leave a comment

Blog at WordPress.com.

Up ↑