[wp-trac] [WordPress Trac] #40872: Add $item argument to start_lvl (nav menu walker)

WordPress Trac noreply at wordpress.org
Mon Sep 29 16:37:37 UTC 2025


#40872: Add $item argument to start_lvl (nav menu walker)
-------------------------------------+-----------------------------------
 Reporter:  mireillesan              |       Owner:  (none)
     Type:  feature request          |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Menus                    |     Version:  4.7.5
 Severity:  normal                   |  Resolution:
 Keywords:  reporter-feedback close  |     Focuses:  javascript, template
-------------------------------------+-----------------------------------
Changes (by callumbw95):

 * keywords:  reporter-feedback => reporter-feedback close


Comment:

 Hi @mireillesan,

 I have just taken a look into this, and agree that some way of identifying
 the current item you are on within `start_lvl()` would be  a useful
 addition to the function. However having used the function myself there is
 already a work around due to the fact we have access to `start_el()` as
 well as the `$data_object` from within there.

 As the `Menu_Walker` is a class within PHP we can do the following to
 store our current item, and make this accessible to the `start_lvl()`
 function with something like the following:

 {{{#!php
 <?php
 class ThemeTruck_Nav_Walker extends Walker_Nav_Menu
 {
         private $current_item;

         public function start_lvl( &$output, $depth = 0, $args = null ) {
                 $item = $this->current_item;
         }

         public function start_el( &$output, $item, $depth = 0, $args =
 null, $id = 0 ) {
                 $this->current_item = $item;
         }
 }
 }}}

 This is a little bit more hands on, but I believe this is a valid solution
 to the problem you experienced. Whilst I am in favour of having the
 `$item` variable passed to the `start_lvl()` function directly, because we
 can get around this issue when creating our own walkers, I am not sure how
 much traction this will get. Due to this and the fact this ticket has been
 sitting for 8 years and 2 major releases now, I am going to attach the
 `close` tag, however if you have anymore thoughts on this please reopen
 the ticket. 😃

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/40872#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list