How to Create a WordPress Plugin That Displays “Hello World”
Create the Plugin File
The first step is to create a new directory inside your WordPress installation — wp-content/plugins.
This folder contains all installed plugins for your website.
Let’s name our directory my-first-plugin. Inside it, create a PHP file called my-first-plugin.php.
To make WordPress recognize your plugin, add the following code right after the opening <?php tag:
/**
* Plugin Name: My First WordPress Plugin
* Plugin URI: https://codewan.com
* Description: This is my first plugin.
* Version: 1.0.0
* Author: Ivan Balkanov
* Author URI: https://codewan.com
* License: GPL2
*/
Adding Functionality
This block is a comment that WordPress reads and displays in the “Plugins” section of your admin dashboard.
It provides essential information such as the plugin’s name, version, and author.
The minimum required field is Plugin Name: — that alone is enough for WordPress to list it as an available plugin.
Now let’s add our first function to display “Hello, World!” in the site header:
add_action('wp_head', 'hello_world');
function hello_world() {
echo 'Hello, World!';
}
The hello_world() function simply prints “Hello, World!”.
The key part is the first line — it tells WordPress to hook the function into the site’s header using add_action().
That’s the fundamental idea behind actions and hooks.