Bird
0
0

Given the code below, what will be the output when the page loads?

medium📝 component behavior Q13 of 15
Wordpress - WordPress Hooks System
Given the code below, what will be the output when the page loads?
function greet() {
  echo 'Hello!';
}
add_action('wp_footer', 'greet');
remove_action('wp_footer', 'greet');
AHello!
BNo output
CPHP error
DHello!Hello!
Step-by-Step Solution
Solution:
  1. Step 1: Understand add_action effect

    The function greet is added to run on the wp_footer hook, so it would print 'Hello!'.
  2. Step 2: Effect of remove_action

    Immediately after adding, remove_action stops greet from running on wp_footer.
  3. Final Answer:

    No output -> Option B
  4. Quick Check:

    remove_action cancels added hook = no output [OK]
Quick Trick: Remove cancels add, so no output appears [OK]
Common Mistakes:
  • Assuming add_action still runs after remove_action
  • Expecting duplicate output
  • Thinking code causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes