Only show top-level links in site navigation

This seems like it should be easy to do, but I’ve not been able to find or work out a solution.

I’m using the Starkers theme and WordPress 3.0.4, and my site auto-generates its navigation as per normal. I would like however the navigation to only show the top level pages, i.e. not display links to any pages that are children of other pages.

Read More

This is the code I am currently using.

<?php wp_nav_menu( array( 'container' => 'nav', 'fallback_cb' => 'starkers_menu',
'theme_location' => 'primary' ) ); ?>

I would like to hide the child links programmatically, but I am prepared to use CSS if someone can instead advise how to assign specific classes to the child links.

Thanks in advance for any help.

**edit 2**

I’ve tracked down the actual function I am using, called starkers_menu (below). However adding depth to this, or even removing the other exclusions and just using depth doesn’t work either:

function starkers_menu() {
    echo '<nav><ul>';
    wp_list_pages('depth=1&exclude=4,19&title_li=');
    echo '</ul></nav>';
}

Related posts

Leave a Reply

1 comment

  1. Had you tried depth argument (see wp_nav_menu() documentation)?

    Also do I understand right that you do not setup menu manually and let theme generate it with custom callback that you have in your code?

    Update

    Same answer – try depth argument, only this time in wp_list_pages() call in starkers_menu() function. It should work, unless that function is never processed and not available at the time of menu running.

    Do you use latest version of theme?.. If not consider updating.