Bird
0
0

You want to add a custom header message only on the homepage and a footer copyright notice on all pages. Which is the best way to do this in your theme's functions.php?

hard📝 state output Q15 of 15
Wordpress - Custom Theme Development
You want to add a custom header message only on the homepage and a footer copyright notice on all pages. Which is the best way to do this in your theme's functions.php?
AUse <code>add_filter</code> instead of <code>add_action</code> for both hooks
BAdd both messages inside <code>wp_footer</code> hook without conditions
CUse <code>add_action('wp_head', function() { if (is_front_page()) echo '<div>Welcome Home!</div>'; });</code> and <code>add_action('wp_footer', function() { echo '<div>© 2024 MySite</div>'; });</code>
DAdd both messages inside <code>wp_head</code> hook without conditions
Step-by-Step Solution
Solution:
  1. Step 1: Use conditional check for homepage header

    Use is_front_page() inside wp_head hook to add header message only on homepage.
  2. Step 2: Add footer message on all pages

    Use wp_footer hook without condition to add footer copyright on every page.
  3. Final Answer:

    Use add_action('wp_head', function() { if (is_front_page()) echo '<div>Welcome Home!</div>'; }); and add_action('wp_footer', function() { echo '<div>© 2024 MySite</div>'; }); -> Option C
  4. Quick Check:

    Use conditional in wp_head, unconditional in wp_footer [OK]
Quick Trick: Use is_front_page() condition inside wp_head hook [OK]
Common Mistakes:
  • Adding all messages unconditionally
  • Using add_filter instead of add_action
  • Putting footer message in wp_head hook

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes