Bird
0
0

What will be the output of this code snippet?

medium📝 component behavior Q13 of 15
Wordpress - WordPress Hooks System
What will be the output of this code snippet?
function greet() {
  echo 'Hello!';
}
add_action('wp_footer', 'greet');
Assuming the theme calls do_action('wp_footer'); in the footer.
AThe text 'Hello!' will appear in the footer
BNothing will be displayed
CA PHP error will occur
DThe text 'greet' will appear in the footer
Step-by-Step Solution
Solution:
  1. Step 1: Understand add_action and do_action

    add_action attaches 'greet' function to 'wp_footer' hook. When do_action('wp_footer') runs, it calls 'greet'.
  2. Step 2: Analyze the greet function output

    The greet function echoes 'Hello!', so this text will appear where the footer hook runs.
  3. Final Answer:

    The text 'Hello!' will appear in the footer -> Option A
  4. Quick Check:

    do_action triggers greet, which echoes 'Hello!' [OK]
Quick Trick: do_action runs hooked functions, output appears where called [OK]
Common Mistakes:
  • Thinking nothing happens without explicit call
  • Confusing function name string with output
  • Expecting errors from correct hook usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes