This tutorial shows you how to display a different nav menu to your default menu settings on specific pages.
It applies to themes which include a header.php like Twenty Twelve which is the theme the code is tested on.
Line 45 of the the Twenty Twelve themes header.php file includes this code:
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
Simply replace that line with this code:
<?php if ( is_page('members-downloads') ) : ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu' => 'wp-sites', 'menu_class' => 'nav-menu' ) ); ?>
<?php else : ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu' => 'Primary', 'menu_class' => 'nav-menu' ) ); ?>
<?php endif; ?>
The code above includes a conditional tag to change the default menu in the Primary position to a menu named wp-sites only when the page with the slug members-downloads is loaded.
You can easily modify the conditional tag and menu name to suit your own requirements.
Note: When modifying code in parent theme files, its best practice to copy the file over to a child theme and modify there as any changes to the code in the parent theme will be lost when its updated. Child themes aren’t generally updated.
This solution does not apply to Genesis.
To change the nav menu for a specific page in Genesis you can use the Genesis Simple Menus plugin.
Was This Tutorial Helpful?