Output existing wp_nav_menu with a custom walker

I am trying to output another wp_nav_menu if an existing wp_nav_menu item has a specific class like this..

/* Custom Walker */
class IBenic_Walker extends Walker_Nav_Menu {

// Displays start of an element. E.g ‘<li> Item Name’
// @see Walker::start_el()
function start_el(&$output, $item, $depth=0, $args=array(), $id = 0) {
$object = $item->object;
$type = $item->type;
$title = $item->title;
$description = $item->description;
$permalink = $item->url;

$output .= “<li class='” . implode(” “, $item->classes) . “‘>”;
$output .= ‘<a href=”‘ . $permalink . ‘”>’;
$output .= $title;
$output .= ‘</a>’;

/* If Item Class Is shop_nav */
if (in_array(“shop_nav”, $item->classes)) {
$output .= ‘<ul class=”sub-menu”>
‘ . wp_nav_menu( array(
‘theme_location’ => ‘col_1’,
‘menu_id’ => ‘col_1’,
‘menu_class’ => ‘col_1’,
‘container’ => ”,
) ) . ‘
</ul>’;
}

$output .= ‘</li>’;

}
}

This is not working as expected, can anyone see where I am going wrong?

Read more here:: Output existing wp_nav_menu with a custom walker

Leave a Reply

Your email address will not be published. Required fields are marked *