How to Write a Very Simple WordPress Plugin

To write a simple WordPress plugin, follow these steps:

  1. Create a new folder in the “wp-content/plugins” directory of your WordPress installation. Name the folder after your plugin, using all lowercase letters and separating words with dashes (e.g. “my-simple-plugin”).
  2. Create a new PHP file with the same name as your plugin folder (e.g. “my-simple-plugin.php”) and open it in a text editor.
  3. Add the plugin header to the top of the PHP file. The plugin header is a block of comment lines that contain information about your plugin, such as the plugin name, author, version, and description. The header should look like this:
Plugin Name: My Simple Plugin
Plugin URI:
Description: A simple plugin that does something cool.
Version: 1.0
Author: Your Name
Author URI:
License: GPLv2 or later
  1. Write the main function of your plugin. This is the core functionality of your plugin, and it should be wrapped in a PHP function with a unique name. For example:
function my_simple_plugin_function() {
    // Plugin functionality goes here
  1. Register your plugin function with WordPress. You can do this by using the “add_action” function, which tells WordPress to execute your plugin function when a specific event occurs. For example:
add_action('wp_head', 'my_simple_plugin_function');

This code tells WordPress to execute the “my_simple_plugin_function” function when the “wp_head” event occurs (which is when the head section of a WordPress page is being generated).

  1. Save the PHP file and upload it to the plugin folder you created in step 1.
  2. Log in to your WordPress dashboard and go to the Plugins page. You should see your plugin listed in the plugin list.
  3. Activate your plugin by clicking on the “Activate”