Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to change to a different menu using conditional tags but using the same theme location?

I have 2 menu's created which I want to display conditionally in the same them location which is the secondary menu location.

share|improve this question
add comment

1 Answer

Yes, You can easily switch menus using conditional tags.

For example If you want to show different menu for logged in user and non-logged in user then It may be like:

<?php
 if ( is_user_logged_in() ) {
 wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) );
} else {
 wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) );
}
?>

Read WordPress Codex

share|improve this answer
    
This is not for loggedin user. Its using conditional tags for in_category(news). If not in news category, display the default secondary nav menu. Both menu's need to use the same theme location but are different menus with different names. How do i do this? –  sunshine Sep 4 '13 at 13:19
    
Of course, You can do that with a category. replace is_user_logged_in() with in_category('news'). Check the single quote. Read this for use of in_category –  Anand Kumar Sep 4 '13 at 13:35
    
I did that but it didn't work. You can only assign one menu per theme location. Did you test the code? –  sunshine Sep 4 '13 at 13:40
    
It's good idea to share code you used. Read this for how to ask questions on here. It will also help you to get better answers quickly I am pretty sure that you can have more than one navigation at a place. Modify your question and share the code you used. –  Anand Kumar Sep 4 '13 at 13:54
    
You can't assign more than one menu to the same theme location. Did you test your code? –  sunshine Sep 4 '13 at 13:58
show 4 more comments

Your Answer

 
discard

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.