Bird
0
0

What is wrong with this custom walker class code?

medium📝 Debug Q14 of 15
Wordpress - Custom Theme Development
What is wrong with this custom walker class code?
class Custom_Walker extends Walker_Nav_Menu {
  function start_el($output, $item, $depth=0, $args=null, $id=0) {
    $output .= "
  • " . $item->title . "
  • "; } }
    AThe class should extend Walker_Page, not Walker_Nav_Menu
    BThe method name should be end_el, not start_el
    CThe $item parameter is missing
    DThe $output parameter should be passed by reference
    Step-by-Step Solution
    Solution:
    1. Step 1: Check method signature requirements

      In Walker_Nav_Menu, start_el must accept &$output by reference to modify it properly.
    2. Step 2: Identify the error in parameter passing

      The code uses $output without & reference, so changes won't affect the original output string.
    3. Final Answer:

      The $output parameter should be passed by reference -> Option D
    4. Quick Check:

      $output must be & passed to modify output [OK]
    Quick Trick: Remember $output needs & to update menu HTML [OK]
    Common Mistakes:
    • Forgetting & on $output parameter
    • Mixing start_el with end_el method
    • Extending wrong walker class

    Want More Practice?

    15+ quiz questions · All difficulty levels · Free

    Free Signup - Practice All Questions
    More Wordpress Quizzes