Change language

A step-by-step guide to creating your first WordPress plugin

This tutorial will show you how to develop your first WordPress plugin. Prerequisites :
  • Installing WordPress
  • Basic knowledge PHP
Steps to make a plugin -
  • Go to WordPress Installation -> WordPress / wp-content / plugins. 
  • Create here a new folder and name it "Plugin Name", in this case "First Plugin". 
  • Then create a new PHP file in this folder and name it the same as in this case First-Plugin.php folder
  • Now we will add the name of our plugin. Add the plugin name attached to the PHP comment in the file. 
    First-Plugin.php PHP file code -
    / **
    * Plugin name: First plugin
    ** /
    ?>
  • Now go to your WordPress dashboard-> Plugins.Here you can see our newly created plugin and its name. 
  • We should not leave the description blank, as it helps the user know what the plugin is for. so let’s add a description of our plugin by adding a new comment line after “Plugin Name:” with the title “Description” and save it. PHP file code First-Plugin.php -
    / **
    * Plugin name: First plugin
    * Description: This is my first plugin.
    ** /
    ?>
  • We have successfully added our plugin description, now go to Dashboard-> plugin to see what it looks like. 
  • Next we will add some functionality to our first plugin. We’ll add a basic function called first_plugin() that prints “HELLO This is my first plugin” and its shortcode that allows it to be placed on a WordPress post or page. 
    Code -
    / **
    * Plugin name: First plugin
    * Description: This is my first plugin.
    ** / function First_Plugin() { $content = " HELLO This is my first Plugin. " ; return $content ; } add_shortcode ( ’ myplugin’ , ’First_Plugin’ ) ?>
  • We use the WordPress shortcode function to display the output of this function. Go to Messages-> edit or create a new message. Add a shortcode for the plugin you just created. 
    Shortcode - [myplugin]
  • To see the output of the plugin, browse the website and open the post where we added our plugin shortcode. 
    This is how it looks
  • Now, to use this plugin functionality multiple times, we can use this shortcode multiple times. Just add the shortcode wherever we need this output. 
  • Check message for updated output, here we get two identical suggestions because we used the shortcode in this post twice.
  • We now have our plugin that returns a value and can be used anywhere using a shortcode.

    Shop

    Best laptop for Sims 4

    $

    Best laptop for Zoom

    $499

    Best laptop for Minecraft

    $590

    Best laptop for engineering student

    $

    Best laptop for development

    $

    Best laptop for Cricut Maker

    $

    Best laptop for hacking

    $890

    Best laptop for Machine Learning

    $950

    Latest questions

    NUMPYNUMPY

    psycopg2: insert multiple rows with one query

    12 answers

    NUMPYNUMPY

    How to convert Nonetype to int or string?

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Javascript Error: IPython is not defined in JupyterLab

    12 answers

    Wiki

    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | cv2.circle () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method