Wednesday, November 12, 2025

#2 Modules : Hooks & Filters

WordPress Plugin Tutorial - Modules 1 & 2

🎓 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:
  1. Action Hooks → Let you run code at a specific event (e.g., wp_footer)
  2. Filter Hooks → Let you modify data before it’s displayed (e.g., the_content)


🧩 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!


© 2025 WordPress Plugin Learning Demo | Built with Prism.js | Modules 1–2

No comments:

Post a Comment

17 Auto pages Manu

 Prompt: can you create plugin to add menu at top for pages like login, contactus, tutorials, projects, equivalence. Create the above pages ...