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 have 4 different menus on my website.

Right now I'm using the solution to a problem I posted here in order for the menu to display using the CSS framework I'm making use of.

Each of these menus has a number of child pages, and on these child pages I'd like to display the corresponding menu. For example, the About Us children would only show the about us menu, the contact children would only show the contact us menu.

My functions.php showing the menus is:

 function register_my_menus() {
   'about-menu' => __( 'About Us Menu' ),
   'how-menu' => __( 'How Do I Menu' ),
   'services-menu' => __( 'Our Services Menu' ),
   'online-menu' => __( 'Do It Online Menu' )
add_action( 'init', 'register_my_menus' );

In my mind I imagine it to be a script in the header.php that would just have a series of if statements.

I appreciate your help.

EDIT: I've actually solved this by using a series of if statements and using a php include within the pages.

For anyone interested, I've used the solution posted above, with the following code:

  if ( $post->post_parent == '1' || is_page(1) ) { 
    $menu_name = 'about-menu'; 
    // and so on..
  elseif ( $post->post_parent == '2' || is_page(2) ) {
    $menu_name = 'contact-menu';
    // and so on..

Granted it may not be the best way of doing it, what with having a great deal of repeated code, but it works for me, and I hope it can benefit others in the future.

share|improve this question

On each (child) page, get the top-most parent, then display the according menu.

Here is a blue-print of what I just described (you may have to change this and that to make it behave like you want it to). Simply put the following code where you currently have your menu set up (in your header.php file, I suppose):

if (is_page()) {
    $id = get_the_ID();
    if (count($ancestors = get_ancestors($id, 'page')))
        $id = $ancestors[count($ancestors)-1];
} else
share|improve this answer
wp_nav_menu('default-menu'); this function is not working. Officially it accepts array. Can you fix that please? – Vivek Sancheti Feb 13 at 6:54

Sure you can. I've done something similar with a couple of different ways.

One way would be to create a page template for each of the pages and call the navigation into the template. If you're using the Genesis Framework in a child theme, it's extremely simple.

Another way would be to register a new widget area, and display the menus here/ Each menu would be a new item in that widget area, and you can use something like Widget Logic to have it shown on particular pages.

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.