WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a second level navigation in WordPress. I've found lots of examples, but none of them seem to do exactly what I want. This code below has me almost there, but I want an active class or better yet a way to only show the sub navigation if I'm on it. It would be great it WordPress had a depth_start option along with depth.


link2 (active class)

Code so far:


$parent = array_reverse(get_post_ancestors($post->ID));
$first_parent = get_page($parent[0]);

$args = array(
    'depth'        => 0,
    'child_of'     => $first_parent->ID,
    'title_li'     => __($first_parent->post_title),
    'sort_column'  => 'menu_order',
); ?>

<nav class="sidebar">
        <?php wp_list_pages( $args ); ?> 
share|improve this question
up vote 0 down vote accepted

For now I have decided to use a CSS solution. I realized with the code above I do actually have classes I can work with. For example if you had this navigation in a you could use something like this.

nav.sidebar li li li {
    display: none;
nav.sidebar li li.current_page_item > ul > li, nav.sidebar li li.current_page_ancestor > ul > li {
    display: block;

While not ideal, it gets the job done.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.