Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to assign an ID to a sub-menu ul that matches the associated items li in my nav-walker.

Here's the output I'm looking for:

        <a href="menu-item-1" data-parent="#menu-bar" data-toggle="collapse">Menu Item 1</a>
    <ul id="menu-item-1">
        <li>Sub Item</li>
        <li>Sub Item</li>
        <li>Sub Item</li>

Here's the relevant code in my walker

class Roots_Nav_Walker extends Walker_Nav_Menu {

  private $curItem;
  private $curSectionItem;

  function check_current($classes) {
    return preg_match('/(current[-_])|active|dropdown/', $classes);

  function start_lvl(&$output, $depth = 0, $args = array()) {
    $this->curSectionItem = $this->curItem;
    $output .= "\n<ul class=\"panel-collapse collapse\" id=\"".$this->curItem->title."\">\n";
    // $output .= var_dump($this->curItem); // Debug

The var_dump returns null and no output is added. Anything obvious I'm doing wrong?

share|improve this question
Where are you setting $this->curItem, in start_el or one of its filters? –  bonger Aug 5 '14 at 20:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.