🎓 WordPress Plugin Development Tutorial
Learn step-by-step from basics to advanced. Each module includes copyable examples using Prism.js so you can practice easily.
“Hooks are WordPress’s event system — they let your code run at specific times, or modify existing content.”
There are two main types:
🧩 Module 1: Your First Plugin
This simple plugin adds a “Hello, World!” message to your site footer.
- Go to
wp-content/plugins/ - Create a folder named my-first-plugin
- Create a file inside it called my-first-plugin.php
- Paste the following code:
<?php
/*
Plugin Name: My First Plugin
Plugin URI: https://example.com
Description: A simple starter plugin.
Version: 1.0
Author: Your Name
License: GPL2
*/
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');
Activate it in your dashboard under Plugins → My First Plugin. Visit your homepage and you’ll see your message appear.
🧩 Module 2: Understanding Hooks & Filters
WordPress runs thousands of small events (hooks). You can connect your function to them using add_action() or add_filter().
✨ Example: Adding a Footer Message (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: Modifying Post Content (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');
✅ The first example runs at the end of every page. ✅ The second modifies the post content *before* it’s displayed. Together, these are the foundation of every WordPress plugin!
No comments:
Post a Comment