Step 1: Create the Plugin Folder and File
Go to your WordPress installation →
wp-content/plugins/
and create a new folder named
hello-beginner.
Inside it, create a file called
hello-beginner.php.
Step 2: Add the Plugin Header
At the top of your PHP file, include this header (so WordPress recognizes your plugin):
<?php
/*
Plugin Name: Hello Beginner
Description: A tiny starter plugin that displays a message using a shortcode.
Version: 1.0.0
Author: Your Name
License: GPL-2.0+
*/
if (!defined('ABSPATH')) exit; // Security check
Step 3: Add Activation and Deactivation Hooks
These functions run when your plugin is turned on or off:
register_activation_hook(__FILE__, function () {
add_option('hb_message', 'Hello from my first plugin!');
});
register_deactivation_hook(__FILE__, function () {
// Optionally clean up data when the plugin is deactivated
});
Step 4: Add a Simple Shortcode
Now, let’s make a shortcode
[hello_beginner]
that displays your message:
add_shortcode('hello_beginner', function () {
$msg = get_option('hb_message', 'Hello from my first plugin!');
return '<div class="hb-box">' . esc_html($msg) . '</div>';
});
Step 5: Create a Basic Settings Page
Let users customize the message directly from the dashboard:
add_action('admin_menu', function () {
add_options_page(
'Hello Beginner Settings',
'Hello Beginner',
'manage_options',
'hello-beginner',
'hb_render_settings_page'
);
});
function hb_render_settings_page() {
if (isset($_POST['hb_message']) && check_admin_referer('hb_save')) {
update_option('hb_message', sanitize_text_field($_POST['hb_message']));
echo '<div class="updated"><p>Saved!</p></div>';
}
$val = esc_attr(get_option('hb_message', 'Hello from my first plugin!'));
?>
<div class="wrap">
<h1>Hello Beginner Settings</h1>
<form method="post">
<?php wp_nonce_field('hb_save'); ?>
<table class="form-table">
<tr>
<th><label for="hb_message">Message</label></th>
<td><input name="hb_message" type="text" class="regular-text" value="<?php echo $val; ?>"></td>
</tr>
</table>
<?php submit_button('Save Changes'); ?>
</form>
</div>
<?php
}
Step 6: Add Some Style (Optional)
Create a folder named assets inside your plugin and add a file style.css:
.hb-box {
padding: 12px;
border: 1px solid #ddd;
border-radius: 8px;
background: #f9f9f9;
}
Then enqueue it in your PHP file:
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('hb-style', plugins_url('assets/style.css', __FILE__));
});
Step 7: Activate and Test
Go to your WordPress Dashboard → Plugins → Hello Beginner → Activate.
Then edit any post or page and insert
[hello_beginner].
Congratulations! You’ve just created your first working WordPress plugin.