I'm using wp_list_pages('title_li=') on my site.

Some of my pages do have subpages, however I don't want to list them unitl I'm on an actual parent page that has subpages.

So imagine my front-page:

— About Us
— Gallery
— Kitchen
— Disclaimer

When clicking on Gallery (and Gallery has two subpages) I want them to be listed as well.

— About Us
— Gallery
  — Subpage 1
  — Subpage 2
— Kitchen
— Disclaimer

How am I going to do this with the wp_list_pages() function?

2 Answers 2


This would probably be better achieved using CSS. First, you hide all .children:

.page_item .children {
  display: none;

Then, you show the current_page_item's children:

.current_page_item .children {
  display: block;

try the following:

$output = wp_list_pages(depth=1);

expl: depth (integer) This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).

    0 (default) Displays pages at any depth and arranges them hierarchically in nested lists
    -1 Displays pages at any depth and arranges them in a single, flat list
    1 Displays top-level Pages only
    2, 3 … Displays Pages to the given depth 

For mor info can have a look here

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.