Dynamic menu options based on user
-
I am building a multisite network which uses a single set of menus across all child sites, depending on whether or not a user is logged in. What I am attempting to do, is add various menu buttons/options according to which type of user is logged in and who that particular user is.
Currently, my header loads one of two menus based on a user being logged in. This will be expanded based on user type once I get the other portion solved.
<?php if (is_user_logged_in()) { switch_to_blog(1); wp_nav_menu(array( 'theme_location' => 'user-menu', 'container_class' => 'nav-center', )); restore_current_blog(); } else { switch_to_blog(1); wp_nav_menu(array( 'theme_location' => 'public-menu', 'container_class' => 'nav-center', )); restore_current_blog(); } ?>
The problem with this approach is that the menu is built in the GUI rather than code. I’m assuming I will need a custom walker for this to work, but am not entirely sure how to get this accomplished.
What I need is for the
user-menu
to change the items within the menu based on which user is currently logged in. For example, if user john-doe is logged in, there should be menu options such as:
“https://mysite.com/john-doe/link-1”
“https://mysite.com/john-doe/link-2”And if user jane-smith is logged in, the same menu locations should instead point to:
“https://mysite.com/jane-smith/link-1”
“https://mysite.com/jane-smith/link-2”Would a custom walker allow for this?
- The topic ‘Dynamic menu options based on user’ is closed to new replies.