Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Wordpress - Themes and Appearance
Identify the error in this code snippet:
function my_widgets_init() {
register_sidebar('name' => 'Main Sidebar', 'id' => 'main-sidebar');
}
add_action('widgets_init', 'my_widgets_init');
Awidgets_init hook is incorrect
BThe function name is invalid
Cregister_sidebar() expects an array, not separate arguments
Dadd_action() is missing a priority argument
Step-by-Step Solution
Solution:
  1. Step 1: Check register_sidebar() parameter format

    It requires a single array argument with keys like 'name' and 'id'.
  2. Step 2: Identify the incorrect argument passing

    The code passes separate arguments instead of an array, causing an error.
  3. Final Answer:

    register_sidebar() expects an array, not separate arguments -> Option C
  4. Quick Check:

    register_sidebar() needs array argument [OK]
Quick Trick: Always pass an array to register_sidebar() [OK]
Common Mistakes:
  • Passing multiple arguments instead of array
  • Wrong hook name
  • Ignoring function naming conventions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes