Diving into WordPress plugin development can seem daunting, but every journey begins with a single step. For developers, that step is almost always the legendary ‘Hello World’ program. This article will guide you through creating your very first WordPress plugin, teaching you the fundamental structure and how to display a simple message using a shortcode.
Prerequisites
Before you begin, ensure you have a local WordPress development environment set up (e.g., using Local by Flywheel, XAMPP, MAMP, or Docker). You’ll also need a code editor (like VS Code or Sublime Text).
Step 1: Create Your Plugin Folder
Navigate to your WordPress installation’s wp-content/plugins/ directory. Here, create a new folder for your plugin. It’s a best practice to use a unique, descriptive, and lowercase name, with hyphens instead of spaces. For this tutorial, let’s name it my-hello-world-plugin.
wp-content/plugins/
└── my-hello-world-plugin/Step 2: Create Your Main Plugin File
Inside your newly created my-hello-world-plugin folder, create a PHP file. Conventionally, this file shares the same name as your plugin folder. So, create my-hello-world-plugin.php:
wp-content/plugins/
└── my-hello-world-plugin/
└── my-hello-world-plugin.phpStep 3: Add Essential Plugin Header
Open my-hello-world-plugin.php in your code editor. The very first lines of your plugin file must contain a special PHP comment block. This “plugin header” is how WordPress recognizes your plugin and displays its information in the Plugins admin area.
<?php
/**
* Plugin Name: My Hello World Plugin
* Plugin URI: https://yourwebsite.com/my-hello-world-plugin/
* Description: A very simple "Hello World" plugin for WordPress.
* Version: 1.0.0
* Author: Your Name
* Author URI: https://yourwebsite.com/
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: my-hello-world-plugin
* Domain Path: /languages
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Key fields explained:
- Plugin Name: The name displayed in the WordPress admin.
- Plugin URI: The public website for your plugin.
- Description: A brief explanation of what your plugin does.
- Version: The current version number.
- Author: Your name or company name.
- Text Domain: Crucial for internationalization (translating your plugin). It should match your plugin folder name.
The if ( ! defined( 'ABSPATH' ) ) { exit; } line is a standard security measure that prevents direct access to your plugin file outside of the WordPress environment.
Step 4: Your ‘Hello World’ Logic (Shortcode)
Now, let’s add the core functionality: displaying “Hello World.” We’ll use a shortcode, which is a powerful WordPress feature that allows users to insert dynamic content into posts, pages, or widgets using a simple tag like [your_shortcode].
Add the following code below your plugin header and security check:
<?php
// ... (previous plugin header and security check)
function my_hello_world_shortcode() {
return 'Hello World from your first WordPress plugin!';
}
add_shortcode( 'my_hello_world', 'my_hello_world_shortcode' );
Here’s what this code does:
my_hello_world_shortcode(): This is a PHP function that will return the text “Hello World from your first WordPress plugin!”.add_shortcode( 'my_hello_world', 'my_hello_world_shortcode' ): This WordPress function registers your shortcode. The first parameter is the shortcode tag (what users will type), and the second is the function that will be executed when that shortcode is found.
Step 5: Activate and Test Your Plugin
- Log in to your WordPress admin dashboard.
- Go to Plugins > Installed Plugins.
- You should see “My Hello World Plugin” in the list. Click Activate.
- Now, create a new post or page (or edit an existing one).
- In the content editor, simply type
[my_hello_world]. - Publish or update the post/page and view it on the frontend. You should see “Hello World from your first WordPress plugin!” wherever you placed the shortcode.
Conclusion
Congratulations! You’ve successfully built and activated your first WordPress plugin. You’ve learned about the essential file structure, how to properly declare your plugin with header comments, and how to add basic functionality using a shortcode. This ‘Hello World’ foundation is the starting point for developing more complex and powerful WordPress solutions. Keep experimenting, exploring the WordPress Codex, and building upon these fundamentals!

