Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Wordpress - WordPress Hooks System
Identify the error in this code snippet:
function my_func() {
  echo 'Hi';
}
add_action('init', my_func);
AFunction name should be a string in add_action.
BFunction must be declared after add_action.
CHook name 'init' is invalid.
DMissing semicolon after function declaration.
Step-by-Step Solution
Solution:
  1. Step 1: Check add_action parameters

    The function name must be passed as a string, so it should be quoted.
  2. Step 2: Verify other syntax

    The function declaration and hook name are correct; semicolons are properly placed.
  3. Final Answer:

    Function name should be a string in add_action. -> Option A
  4. Quick Check:

    Function names must be strings in add_action [OK]
Quick Trick: Always quote function names in add_action [OK]
Common Mistakes:
  • Passing function names without quotes
  • Thinking function order matters here
  • Misunderstanding hook name validity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes