Actually I think you need to hide or show the menu items based on “User Role”. So here a possible solution would be creating menus for each roles and showing them by condition based on “User Role”. Here is the code-
function the_dramatist_menu_change( $args="" ) {
$current_user = wp_get_current_user();
if( in_array('your-user-role', $current_user->roles) ) {
$args['menu'] = 'Menu 1'; // Menu name as string
} else {
$args['menu'] = 'Menu 2'; // Menu name as string
}
// Add more else if condition based on your user roles.
return $args;
}
add_filter( 'wp_nav_menu_args', 'the_dramatist_menu_change' );
Related Posts:
- Retrieving a list of menu items in an array
- Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()
- Is there an easy way to replace a custom menu link with a page or post?
- Using nonce in menu item
- remove last separator?
- How show sub menu only using wp_nav_menu()
- WordPress built in breadcrumb trail menu?
- Custom Nav Walker menu – Display children count
- How to add menu to Dashboard that can be viewed by all users
- WordPress Export Import Site Navigation Menu
- Bar separated navigation by extending Walker_Nav_Menu
- how do I delete (not exclude) a menu item from navigation bar
- show only a given level in nav menu
- Custom menus created but does not show up in admin panel
- Replace menu tag with tag
- How to display custom post meta in the appearance->menus page
- wp_nav_menu custom walker – child items
- Adding menu items dynamically using wp_nav_menu_objects
- BuddyPress – How to add logout in nav menu
- Where do custom menus get constructed?
- How to remove div container in custom menu?
- Keeping ‘current-menu-item’ highlight of navigation menu?
- Does loading of sub pages in menu cause load to the server?
- Get admin menu link
- Possible to add a dynamic link to a sub-menu via wp_nav_menu_items?
- How can I access the menu ID of an element in a WordPress Nav_Walker
- How to translate menu items?
- echo same menu items across multi-site platform
- How to have the Header show different content on different pages?
- WordPress menu not loading in the admin side appearence-> menu tab
- Is there no straightforward way to display a separate second level using wp_nav_menu()?
- wp_nav_menu() doesn’t work
- Insert other menus as submenus of a main menu
- Change the menu home link to something else
- wp_nav_menu $theme_location parameter ignored
- Count within foreach loop
- Make pages visible to only logged in members
- Insert a div before the wp_nav_menu
- How to create a menu with pages and post categories?
- remove specific classes from menu items
- Why Isn’t My WP_Nav_Menu returning false?
- How to avoid a duplicate query from using wp_nav_menu?
- Wrapping menu’s top-level link and sub-menus in div
- Remove a class from a using Walker
- how avoid the link of the current post in the menu in the sidebar?
- How to convert the argument of wp_list_pages to an array
- wp_bootstrap_navwalker Fatal Error
- wp_nav_menu returns false even though a menu is assigned to it
- How to change the menu mark up with walker_nav_menu class?
- Replace anchor tag with span tag
- How can I query all available public post types and taxonomies?
- If test for “has_nav_menu()” does not return echo when no menu exists
- Add # to submenu URLs automatically
- Automatically Generated Menu pages
- Costum walker with sub menu item count
- Unable to nest categories in menu
- How do I add 3rd level of dropdowns to wp_nav_menu array?
- insert div into a menu item before the link and more
- How to remove empty menu space when creating admin page without menu title using add_submenu_page
- adding pages in underscores.me theme
- Trying to add Newline in Menu item
- How to unlock menu editing
- Can I now add a class in the anchor of my menu item with WordPress 5.4?
- How to add a taxonomy type in Menus?
- WordPress + Bootstrap: Replace primary navigation menu on mobile?
- Multisite Setup – Menu Items To Reference Pages in Different Subdomains
- Header Navmenu glitching in Chrome (but not other browsers)
- how to display different menu according to postid?
- Homepage is not loading
- Disable Mobile Menu, (always show desktop menu)
- Admin: WooCommerce Navigation Menus do not show empty categories search tab
- Using Anchor Link In Nav Menu
- How do I create a new directory to hold the assets for a new menu item?
- How to set active class to the menu of any page coming from a single.php template
- Add Featured Image and Title to wp_nav_menu items
- Sum root term’s entries count from child terms count
- Custom location for menu
- No indication of menu
- Adding a menu item to the main menu
- wp_is_mobile() inside js
- Adding two same css class on menu item
- How to select single category in menu if post have two categories?
- menu is only pulling in one item
- Any reason why widgets/menus get emptied when I updated custom theme code?
- How to get current menu item “CSS Classes” value?
- How to change page location in WordPress
- Use menu structure for permalinks
- Set menu item class into body
- how to keep theme background image, menu or site header image while moving site in sub directory?
- List WordPress Custom Menu’s active parent level’s children as separate menu
- Unable to edit Navigation bar
- Editor user only allow to post on certain categories
- Menu Underline shows without Hover after adding subitems
- How to create a custom WordPress navigation menu?
- Should I custom code drop down menus or use a wordpress plugin?
- How to load css file in my menu in wordpress
- Navigation menu, remove item from desktop
- Jquery dropdown menus working locally, but not in WordPress [duplicate]
- Wrapping my ‘s with
- How to change mobile menu (toggle) icon in WordPress – Full Site Editing?