0

Is there a way to show parent menu descriptions on the first sub menus when using start_lvl ?

function start_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class='sub-menu'><li class='menu-image-container'><div class='menu-image'></div><div class='menu-description'></div></li>\n";
}

I want to put the description of the parent menu item inside the menu-description tags.

I know you can use start_el to get $item->description but is there anyway to be able to pass that through to start_lvl ?

  • 1
    You can use start_el and in that check if item has childs, then out put description... – Rajeev Vyas Mar 5 '15 at 15:02
  • Can you give an example of this please @RajeevVyas ? – Lee Mar 5 '15 at 15:17
  • @Lee if ( $this->has_children ) – TheDeadMedic Mar 5 '15 at 15:37
  • Would one of you be able to provide that as an answer please? I don't understand how you're saying this to be used in the start_lvl – Lee Mar 5 '15 at 15:38
0
// Get menu description as global variable
function add_menu_description( $item_output, $item, $depth, $args ) {
    global $description;
    $description = $item->post_content;
    return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'add_menu_description', 10, 4);

// Submenu walker to add image
class submenu_walker extends Walker_Nav_Menu {
    function start_lvl( &$output, $depth = 0, $args = array() ) {
        if(0 == $depth) {
            global $description;
            $output .= '<ul class="sub-menu">'.
                '<li class="row marginbottom1">'.
                    '<div class="col-sm-8 col-lg-9">'.
                    '<div class="menu-title">'.
                            //$item->title.
                        '</div>'.
                        '<div class="menu-description">'.
                            $description.
                        '</div>'.
                    '</div>'.
                    '<div class="col-sm-4 col-lg-3"><div class="menu-image img-rounded"></div></div>'.
                '</li>';
        } else {
            $output .= '<ul class="sub-menu">';
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.