🎓 WordPress Plugin Development Tutorial
Learn WordPress plugin development step-by-step — each module includes copyable examples with live progress bars powered by Prism.js.
🧩 Module 1: Your First Plugin
This simple plugin adds a “Hello, World!” message to your site footer.
<?php
/*
Plugin Name: My First Plugin
Description: A simple starter plugin.
Version: 1.0
Author: Your Name
*/
function mfp_hello_world() {
echo "<p style='color:green; text-align:center;'>Hello, World! My first plugin works 🎉</p>";
}
add_action('wp_footer', 'mfp_hello_world');
🧩 Module 2: Hooks & Filters
✨ Example: Action Hook
function my_footer_message() {
echo "<p style='text-align:center; color:#00d4ff;'>Thank you for visiting my site!</p>";
}
add_action('wp_footer', 'my_footer_message');
🧠Example: Filter Hook
function add_custom_signature($content) {
if (is_single()) {
$content .= '<p><em>– Thanks for reading!</em></p>';
}
return $content;
}
add_filter('the_content', 'add_custom_signature');
🧩 Module 3: Admin Menu & Settings Page
Now we’ll create an admin menu inside your WordPress Dashboard.
function mfp_add_admin_menu() {
add_menu_page(
'My Plugin Settings',
'My Plugin',
'manage_options',
'my-plugin-settings',
'mfp_admin_page_html',
'dashicons-admin-generic',
20
);
}
add_action('admin_menu', 'mfp_add_admin_menu');
function mfp_admin_page_html() {
if (!current_user_can('manage_options')) return;
echo '<div class="wrap">';
echo '<h1>My Plugin Settings</h1>';
echo '<p>Welcome to your custom settings page!</p>';
echo '</div>';
}
No comments:
Post a Comment