Bird
0
0

Given the code below, what will be the output?

medium📝 component behavior Q4 of 15
Wordpress - WordPress Hooks System
Given the code below, what will be the output?
function say_hello() { echo 'Hello!'; }
add_action('init', 'say_hello');
remove_action('init', 'say_hello');
ANo output
BHello!
CError: function not found
DHello! printed twice
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the hook addition and removal

    The function say_hello is added to 'init' then immediately removed.
  2. Step 2: Determine if say_hello runs

    Since it is removed before 'init' fires, it will not run, so no output.
  3. Final Answer:

    No output -> Option A
  4. Quick Check:

    remove_action prevents function execution = no output [OK]
Quick Trick: Removing action before hook fires stops output [OK]
Common Mistakes:
  • Assuming function runs despite removal
  • Expecting error due to removal
  • Thinking function runs twice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes