How to Create and Publish a WordPress Plugin

Sh Raj - Jul 13 - - Dev Community

How to Create and Publish a WordPress Plugin

Creating and publishing a WordPress plugin can enhance the functionality of WordPress websites. This guide will walk you through the steps to create a simple WordPress plugin and publish it on the WordPress Plugin Directory.

Prerequisites

Before you start, ensure you have the following:

  • Basic knowledge of PHP and WordPress.
  • A local development environment with WordPress installed.
  • Access to a code editor (like VSCode or Sublime Text).

Step 1: Setting Up Your Plugin

  1. Create a Plugin Folder:
    In your WordPress installation, navigate to the wp-content/plugins directory and create a new folder for your plugin. Name it descriptively, for example, my-awesome-plugin.

  2. Create the Main Plugin File:
    Inside your plugin folder, create a PHP file with the same name as your plugin folder, e.g., my-awesome-plugin.php.

  3. Add Plugin Header:
    Open the PHP file and add the following header information at the top:

   <?php
   /*
   Plugin Name: My Awesome Plugin
   Plugin URI: http://example.com/my-awesome-plugin
   Description: A brief description of what your plugin does.
   Version: 1.0
   Author: Your Name
   Author URI: http://example.com
   License: GPL2
   */
Enter fullscreen mode Exit fullscreen mode

Step 2: Writing Your Plugin Code

  1. Add Basic Functionality: Let's create a simple plugin that adds a custom message to the footer of your WordPress site.
   // Add a custom message to the footer
   function my_awesome_plugin_footer_message() {
       echo '<p style="text-align: center;">This is a custom message from My Awesome Plugin.</p>';
   }
   add_action('wp_footer', 'my_awesome_plugin_footer_message');
Enter fullscreen mode Exit fullscreen mode
  1. Save Your Changes: Save the my-awesome-plugin.php file and ensure it's in the wp-content/plugins/my-awesome-plugin directory.

Step 3: Activating Your Plugin

  1. Log in to Your WordPress Admin:
    Go to the WordPress admin panel of your local development site.

  2. Navigate to the Plugins Page:
    Go to Plugins > Installed Plugins.

  3. Activate Your Plugin:
    Find your plugin in the list and click the Activate button.

Step 4: Testing Your Plugin

Visit the front end of your WordPress site and scroll to the footer. You should see the custom message added by your plugin.

Step 5: Preparing Your Plugin for Distribution

  1. Create a Readme File: Create a readme.txt file in your plugin folder. This file provides important information about your plugin.
   === My Awesome Plugin ===
   Contributors: yourname
   Tags: custom footer, custom message
   Requires at least: 5.0
   Tested up to: 6.0
   Stable tag: 1.0
   License: GPLv2 or later
   License URI: http://www.gnu.org/licenses/gpl-2.0.html

   == Description ==
   A brief description of what your plugin does.

   == Installation ==
   1. Upload the `my-awesome-plugin` folder to the `/wp-content/plugins/` directory.
   2. Activate the plugin through the 'Plugins' menu in WordPress.

   == Changelog ==
   = 1.0 =
   * Initial release.
Enter fullscreen mode Exit fullscreen mode
  1. Validate Your Plugin: Ensure your plugin adheres to WordPress coding standards. You can use tools like the WordPress Plugin Boilerplate to structure your plugin properly.

Step 6: Publishing Your Plugin

  1. Create a WordPress.org Account:
    If you don’t already have one, create an account on WordPress.org.

  2. Submit Your Plugin:
    Go to the Plugin Developer Submission page and submit your plugin. You'll need to provide the plugin name, description, and upload a ZIP file of your plugin.

  3. Wait for Approval:
    The WordPress Plugin Review team will review your plugin. This process can take a few days. You'll receive an email once your plugin is approved.

  4. SVN Access:
    Once approved, you'll receive access to the Subversion (SVN) repository where you can manage your plugin's versions and updates. You can follow the SVN guide for more details on how to use SVN.

Conclusion

Congratulations! You've created, tested, and published your first WordPress plugin. This guide covered the basics, but there's much more you can do with WordPress plugins, including adding settings pages, creating custom post types, and more. Explore the WordPress Plugin Developer Handbook for further learning.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .