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 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?

share|improve this question
up vote 3 down vote accepted

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;
share|improve this answer

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

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.