Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
Wordpress - WordPress Hooks System
Identify the error in the following code snippet:
add_action('wp_head', 'my_function', 'high', 2);
function my_function($arg1, $arg2) {
  echo $arg1 . $arg2;
}
AAccepted args must be the third parameter
BFunction name must be passed without quotes
CPriority should be an integer, not a string
DHook name is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter types in add_action

    The third parameter is priority and must be an integer, but 'high' is a string.
  2. Step 2: Verify other parameters

    Function name is correctly quoted, accepted args is fourth parameter, hook name is valid.
  3. Final Answer:

    Priority should be an integer, not a string -> Option C
  4. Quick Check:

    Priority must be integer, not string [OK]
Quick Trick: Priority is always a number, never a string [OK]
Common Mistakes:
  • Passing priority as string
  • Misplacing accepted args parameter
  • Removing quotes from function name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes