First of all sorry if the title isn't clear.

I have a code for my header menu in my functions.php file for listing in a customized way.

function clean_custom_menus2() {
$menu_name = 'headermenu'; // specify custom menu slug
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
    $menu = wp_get_nav_menu_object($locations[$menu_name]);
    $menu_items = wp_get_nav_menu_items($menu->term_id);

    $menu_list = '' ."\n";
    $menu_list .= "\t\t\t\t". '<ul>' ."\n";
    foreach ((array) $menu_items as $key => $menu_item) {
        $title = $menu_item->title;
        $url = $menu_item->url;
        $menu_list .= "\t\t\t\t\t". '<li><a href="'. $url .'">'. $title .'</a></li>' ."\n";
    $menu_list .= "\t\t\t\t". '</ul>' ."\n";
    $menu_list .= "\t\t\t". '' ."\n";
} else {
    // $menu_list = '<!-- no list defined -->';
echo $menu_list;

And I am displaying my menu with this code

<?php if (function_exists(clean_custom_menus2())) clean_custom_menus2(); ?>

So, my problem is that I have a sub-menu in the header menu but it does not shown. Because it is not defined in the function code. How can I define it?

  • Instead of replacing built-in functionality like wp_nav_menu() you would do better to use a custom Walker. Then you don't have to re-invent the wheel. :) – WebElaine Jun 15 '17 at 15:19
  • :)) Thanks for advice. I searched custom Walker and it is exactly for me :) link This question helped me about it. – Solhan Jun 15 '17 at 20:05

Your Answer

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

Browse other questions tagged or ask your own question.