0
votes

I've noticed if you add child pages to a page in the main menu Wordpress automatically puts in a nested list called .children. When hovering over the parent page in the main menu a 'dropdown' menu is displayed.

Basically, I'd like to disable this and I can't way a way to do it within the CMS. I have a menu displaying the child pages in the page sidebar, so I have no use for it.

Any ideas?

My parent theme functions.php has the menu set up like this:

function html5blank_nav()
{
    wp_nav_menu(
    array(
        'theme_location'  => 'header-menu',
        'menu'            => '',
        'container'       => 'div',
        'container_class' => 'menu-{menu slug}-container',
        'container_id'    => '',
        'menu_class'      => 'menu',
        'menu_id'         => '',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'before'          => '',
        'after'           => '',
        'link_before'     => '',
        'link_after'      => '',
        'items_wrap'      => '<ul>%3$s</ul>',
        'depth'           => 0,
        'walker'          => ''
        )
    );
}

So it's pretty standard. I can't find a lot of info on the child menu. I thought it would've been a common request for it to be on/off.

I guess I could create a custom menu in Appearance > Menus but I'd rather stay away from that if possible as it could be a pain to manage future additional pages?

Hope someone can help! :)

1
Looks like your current menu setup is adding pages to menus automatically. If you had custom menu functionality enabled, there is simple uncheck/checkbox to decide if you want to add future pages automatically to Menus or not... - Mohsin
If you prefer to keep it via theme as you mentioned. In your above code you have this line 'depth' => 0, here Zero means all levels, you may set it to 1 to make it Top pages level only... - Mohsin
Thanks, that works great. I had no idea what 'depth' did! I've decided I want to hide the 'home' link from my main navigation. So maybe a custom menu might be the way to go instead with that in mind? - user1406440
I have posted it as answer so you may mark it resolved please. To hide any specific link from menu, you might use css's display:none, for homepage WP assigns specific class like .menu-item-home so you may target it in the css. - Mohsin
Thanks again, already done! :) - user1406440

1 Answers

2
votes

To disable child pages appearing in the menu, in your code, change depth => 0 to 1.

So it will become:

function html5blank_nav()
{
    wp_nav_menu(
    array(
        'theme_location'  => 'header-menu',
        'menu'            => '',
        'container'       => 'div',
        'container_class' => 'menu-{menu slug}-container',
        'container_id'    => '',
        'menu_class'      => 'menu',
        'menu_id'         => '',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'before'          => '',
        'after'           => '',
        'link_before'     => '',
        'link_after'      => '',
        'items_wrap'      => '<ul>%3$s</ul>',

'depth' => 1,

        'walker'          => ''
        )
    );
}

It limit pages to top level pages only and child pages are ignored and not added to automatic Menu generation.