How To Create a WordPress Plugin | Basics

WordPress is getting more popular each day, not only as a blogging platform, but as a content management system. One of the reasons for popularity of WordPress is its modular architecture. You can extend it without modifying the core code by adding plugins.

Here’s a tutorial on creating a very simple WordPress plugin to understand how the plugin system fits into the WordPress machine. Before starting to write your plugin, decide a unique name for it so that it doesn’t conflict with any existing WordPress plugin.

Start by creating a php file with the name same as your plugin file, my-first.php.

Note that you can split your plugin’s code into multiple files and folders as it gets more complex, but for our purpose, a single file will be sufficient.

If you want to submit your plugin to WordPress plugin repository, you must also include a readme file describing your plugin, no matter how simple your plugin is.

The content from this file is displayed on the plugin’s listing on WordPress plugin repository. You can see the readme file format here.

Open my-first.php file and put the standard WordPress plugin header code in it.

Plugin Name: MyFirst
Plugin URI:
Description: The Simplest WordPress Plugin.
Version: 1.0
Author: Mayur Somani
Author URI:
License: GPL2


Now save this file and put it in the wp-content/plugins folder in your test WordPress installation. Now go to, Plugins > Installed Plugins in your dashboard. You’ll see your plugin there with the information from the plugin header you just created.

You can even activate it but it will not do anything as we have not added any code to it yet.

Now you can add code to it depending upon your requirements. You can use WordPress hooks to modify or filter data, or you can add or fetch content from the database.

Here I will show you how to simply echo a string in your WordPress theme, using this plugin. Open my-first.php and add this code just below the plugin header.

function my_first()
echo "<p>My First Wordpress Plugin Works!</p>";

Now activate this plugin if you haven’t done so already. Now edit any of the template files in your theme to add this code in it, say in single.php.

<?php if(function_ exists('my_first')) { my_first(); } ?>

If you are wondering why I didn’t simply called the my_first(); then you must check the correct way to add plugin functions in theme.

Now open the website and go to any single post, and you’ll see that the plugin works!

So you learned how to create a very basic WordPress plugin here. In future installments of this tutorial, I will cover more on creating WordPress plugins, so stay tuned.


  1. Tom | Build That List:

    I always wondered how hard it was to create a plugin. I guess the hard part is coming up with something original and then coding that.

  2. Rohit Sane:

    This is okay! Just printing something is okay! But can you give us some fair idea about how other plugins are created, not just printing. I know different ideas are executed differently!

  3. WebVeins:

    Its so simple. Where is the tutorial for advanced plugins with database interaction?

  4. Kiran Ruth R:

    It’s be nice if you can explain the whole hook system in wordpress and in turn how to use them in plugins . That would be really great :)

  5. Dion GeBorde:

    Hi, thanks for making this tutorial. I find it interesting that I’ve come across three tutorials now that describe creating a basic “echo” plugin that requires you to manually enter the php code into one of the WordPress templates. Is there a reason that you don’t just make that part of the plugin to begin with? Also, do you have any plans to write an article about object-oriented plugins using classes?

  6. Dalle:

    Nice tutorial on how to create a WordPress plugin. Now I just need to figure out how to get the rest of my idea to work.