0

Does anyone know how to add an active class onto the side navigation page you are currently on?

The code below works fine but doesnt add an active class

<ul class="side-nav">
    <?php global $post;
    $current_page_parent = ( $post->post_parent ? $post->post_parent : $post->ID );

    wp_list_pages( array(
         'title_li' => '',
         'child_of' => $current_page_parent,
         'depth' => '1' ));
    ?>
</ul>
  • possible duplicate of Add class to the items in wp_list_pages – Howdy_McGee Apr 8 '14 at 21:37
  • Well even using the code on that link doesn't output any classes on the li – adam Apr 8 '14 at 22:07
  • wp_list_pages() should add a class to the containing list item, so on the current page it will say something like <li class="current_page_item">...</li> so you can style it like li.current_page_item a – Howdy_McGee Apr 9 '14 at 15:57
  • Nope no classes are being spat out, wonder if its to do with using a custom nav? – adam Apr 10 '14 at 17:39

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.