Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Wordpress - WordPress Hooks System
Identify the error in this code snippet:
function add_custom_text() {
  echo 'Custom Text';
}
add_action('init', add_custom_text());
AThe function add_custom_text is not defined
BThe hook name 'init' is invalid
CMissing semicolon after function definition
DThe function add_custom_text is called immediately instead of being hooked
Step-by-Step Solution
Solution:
  1. Step 1: Check how add_action expects arguments

    add_action expects the second argument as a function name string, not a function call.
  2. Step 2: Identify the mistake in the code

    Using add_custom_text() calls the function immediately and passes its result, which is incorrect.
  3. Final Answer:

    The function add_custom_text is called immediately instead of being hooked -> Option D
  4. Quick Check:

    Pass function name as string, not call it [OK]
Quick Trick: Use function name string, not function call in add_action() [OK]
Common Mistakes:
  • Calling function instead of passing name
  • Assuming hook name is wrong
  • Missing semicolon confusion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes