I have a menu within the sidebar of my site. When you click on the child element of the menu, the li tag adds a current_page_item class to the li tag.

When you land on the page its the parent page and I want the "Overview" li below to add a current_page_item class like its child pages. Does anyone know how to achieve this?

 $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
 $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
 if ($children) {
 $parent_title = get_the_title($post->post_parent);

Related Pages

<!-- <li class="current_page_item"> -->
  <a href="<?php echo get_permalink($post->post_parent) ?>">Overview</a>
 <?php echo $children; ?>
 <?php } ?> 

<div class="sidebar-widget">
 <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('page-sidebar')) ?>

Thanks for your help

1 Answer 1


I believe that it will be hard for you to accomplish that without some javascript because you are adding the link manually. However, you can achieve the same thing in another way:

Most wordpress themes come with a body_class() function in the <body> tag. That function adds several classes to the body tag that allows you to better target your content with css. One of the classes added is page-id-* (where * is the page ID). You can read more about body_class here.

So, in your case, the Overview page will also have that page-id-* class that you can use to target your menu.

In you css you can write something like:

.page-id-20 ul.sidebar-menu li:first-child{



This assumes a few things:

  1. The Overview page ID is 20. It could be any number, just look at your source code to find out. Or look in the backend to find out the page id.

  2. You have given a class .sidebar-menu to your UL side menu. (Right now, your code doesn't have a class)

  3. The Overview link is always the first link on the list.
  4. The menu is the same on every page.
  • I am glad it worked.
    – gdaniel
    Commented Dec 8, 2014 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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