0
0
Wordpressframework~30 mins

add_action and add_filter in Wordpress - Mini Project: Build & Apply

Choose your learning style9 modes available
Using add_action and add_filter in WordPress
📖 Scenario: You are building a simple WordPress plugin to customize how your site works. You want to add a message to the footer and change the title of posts before they show on the site.
🎯 Goal: Build a WordPress plugin that uses add_action to add a footer message and add_filter to modify post titles.
📋 What You'll Learn
Create a function called custom_footer_message that echoes a footer message
Use add_action to hook custom_footer_message to the wp_footer action
Create a function called modify_post_title that adds ' - Custom' to the post title
Use add_filter to hook modify_post_title to the the_title filter
💡 Why This Matters
🌍 Real World
WordPress developers use add_action and add_filter to customize themes and plugins safely and flexibly.
💼 Career
Understanding hooks is essential for WordPress plugin and theme development jobs.
Progress0 / 4 steps
1
Create the footer message function
Create a function called custom_footer_message that echoes the text 'Thank you for visiting!'.
Wordpress
Need a hint?

Use the function keyword to create custom_footer_message. Inside, use echo to show the message.

2
Hook the footer message function to wp_footer
Use add_action to hook the custom_footer_message function to the wp_footer action.
Wordpress
Need a hint?

Call add_action with the first argument as 'wp_footer' and the second as 'custom_footer_message'.

3
Create the post title modification function
Create a function called modify_post_title that takes one parameter $title and returns the title with ' - Custom' added at the end.
Wordpress
Need a hint?

Define modify_post_title with $title as input. Use return to add ' - Custom' to the title.

4
Hook the post title modification function to the_title filter
Use add_filter to hook the modify_post_title function to the the_title filter.
Wordpress
Need a hint?

Call add_filter with 'the_title' as the first argument and 'modify_post_title' as the second.