Hiding child pages

When you create a child page in WordPress, by default, they would appear in the navigation under the parent page. This, of course, a convenient way for navigation since you don’t have to go into the parent page to look for the child page. However, on the other side, this can look messy if you have 10 child pages for every parent page. Your navigation menu would be ridiculously super long! Obviously you don’t want that. But unless you are using a theme that automatically hides the child pages, otherwise you are stuck with a page long navigation.

However, luckily there’s a convenient way to overcome this matter.

Step 1:
Look for this PHP code:

<?php wp_list_pages(); ?>

The code above lists out your navigation menu/links.

Replace that code with this:

<?php wp_list_pages('depth=1'); ?>

depth=1 lets only parent pages to be shown. If you set it to be 2, all parent pages including their first-level child pages would be shown.

Make sure that you have set the attribute of the child page to be under the parent page, otherwise this won’t work.