Skip to content

Step 3: Adding Functionality

Now that your plugin is activated, it's time to make it do something useful!

Hooks & Filters: The Power of WordPress Plugins ⚡

WordPress provides hooks that allow plugins to modify its behavior without changing core files.

🔹 Types of Hooks:

  1. Action Hooks (Official Docs) – Perform actions at specific points in WordPress.
  2. Filter Hooks (Official Docs)– Modify data before it is displayed.
php
function my_custom_footer_text() {
    echo '<p style="text-align:center;">👋 Thanks for visiting my site!</p>';
}
add_action('wp_footer', 'my_custom_footer_text');

This will display a funny message in the footer of your site! 🎉

Creating Custom Shortcodes 🎯

Shortcodes allow users to insert dynamic content inside pages and posts.

🛠️ Example: Creating a [hello_world] Shortcode

php
function hello_world_shortcode() {
    return "<p>👋 Hello, World! This is a custom shortcode.</p>";
}
add_shortcode('hello_world', 'hello_world_shortcode');

Now, typing [hello_world] in a post will display the message! 🚀

Adding Admin Pages & Custom Settings ⚙️

Let’s create a simple settings page inside the WordPress admin.

🛠️ Example: Creating a Custom Admin Menu

php
function my_plugin_menu() {
    add_menu_page(
        'My Plugin Settings',
        'My Plugin',
        'manage_options',
        'my-plugin-settings',
        'my_plugin_settings_page',
        'dashicons-admin-generic',
        90
    );
}
add_action('admin_menu', 'my_plugin_menu');

function my_plugin_settings_page() {
    echo "<h1>Welcome to My Plugin Settings 🎉</h1>";
}

Now, you'll see a new menu item in the WordPress dashboard! 🎯

🎯 Conclusion

By now, your plugin can: ✅ Modify WordPress with Hooks & Filters

Create Shortcodes for Dynamic Content

Add Admin Pages for Custom Settings

But we’re just getting started!

Built by noobs, for noobs, with love 💻❤️