Ok, so it turns out that by default, $depth
in the end_lvl()
function starts at 0 when it’s a submenu and increments as the depth gets greater. So we need to test if {$depth}
is equal to 0 to apply it only to the first set of submenus:
function end_lvl( &$output, $depth, $args ) {
if( 0 == $depth ) {
$output .= '<div>the div that I want to show only once</div>';
}
$indent = str_repeat( "\t", $depth );
$output .= "{$indent}</ul>\n";
}