-1

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.

1 Answer 1

1

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

10
  • 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, 2013 at 13:19
  • 1
    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 Sep 4, 2013 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, 2013 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. Sep 4, 2013 at 13:54
  • You can't assign more than one menu to the same theme location. Did you test your code?
    – sunshine
    Sep 4, 2013 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.