I'm looking to create and display a separate menu for a specific page. This menu needs to be in the primary location. So for example, on the Home page and the Contact page you would have: Home | About us | Contact. And on the "About us" page, you could show a different menu for example: Menu link 1 | Menu link 2 | Menu link 3. I have been trying for ours to do this with no luck. I literally have been looking at this for so long I don't even know where to start anymore. :( I'm hoping it's something like the code below.. Anyway, any help would be greatly appreciated. Thanks
function my_example_menu() {
register_nav_menu('example-menu',__( 'Example Menu' ));
}
add_action( 'init', 'my_example_menu' );
wp_nav_menu( array(
'theme_location' => 'my-example-menu',
'container_class' => 'my-example-menu-class' ) );
function my_display_example_menu() {
if (is_page('about-us')) {
unregister_nav_menu( 'Primary Navigation' );
register_nav_menu( 'Example Menu' );
}
}
//EDIT
Parent theme nav
<?php truethemes_before_primary_navigation_hook();// action hook ?>
<nav role="navigation">
<?php if('true' == $ubermenu):
wp_nav_menu(array(
'theme_location' => 'Primary Navigation' ,
'depth' => 0 ,
'container' => false ,
'walker' => new description_walker() ));
else: ?>
<ul id="menu-main-nav" class="sf-menu">
<?php wp_nav_menu(array(
'theme_location' => 'Primary Navigation' ,
'depth' => 0 ,
'container' => false ,
'walker' => new description_walker() )); ?>
</ul>
<?php endif; //end uberMenu check ?>
</nav>
<?php truethemes_after_primary_navigation_hook();// action hook ?>
wp_nav_menu()
in your functions.php? It should be in a template file, usuallyheader.php
. Also, ismy_display_example_menu()
hooked to an action? If it's not, then how are you calling that function?is_page('page_slug')
won't work in functions.php. For you situation, I suggest not using the method of unregistering a menu on specific pages. I think you should create a custom field, for pages/posts, where you will select which menu to use on that page/post. And then, write a bit of code in the template file which will read the value of the custom field and pass the corresponding parameter towp_nav_menu()
.header.php
what is in between the two hook? Could you paste it into your question, including the two hooks