Something like this would be more efficient. This is basic PHP by the way, not WP specific.
function add_extra_item_to_nav_menu( $items, $args ) {
$roles = [
'administrator' => [ //Role - slug name
'SCHOOL_NAME-A', //url path - appended to the end
'ADMIN', // can be any name - appended to SHOP NOW button
],
'ROLEABC' => [
'SCHOOL_NAME-B',
'ABC',
],
'ROLEXYZ' => [
'SCHOOL_NAME-C',
'XYZ',
],
];
foreach ( $roles as $role => $menu ) {
if ( current_user_can( $role ) && is_user_logged_in() && $args->menu-5 ) {
$items .= '<li><a href="/product-category/public/' . $menu[0] . '/" class="navShopNow fungula">SHOP NOW ' . $menu[1] . '</a></li>';
break;
}
}
return $items;
}
Related Posts:
- if role is logged in then do something
- how to assign more permission to wordpress author
- Dynamically exclude menu items from wp_nav_menu
- Add custom menu item using wp_nav_menu_items filter
- Custom search filter causes menu and query_posts problems
- Unregister Nav Menu from Child-Theme
- Allow html tags in WordPress Custom Menus Description Field
- Using filters to change href of nav menu page link
- How to apply a class to the second word in menu list item?
- WordPress nav_menu_link_attributes Not Working
- Is it possible to add a filter for the output of nav-menu items in admin?
- Filter menu item to add classes/attributes?
- Edit html for menu items in default frontend menu
- Hide menu items for visitors and filter based on role
- Set Item Order with wp_nav_menu_{$menu->slug}_items
- When at / ( or “home”) my menu doesn’t get a current-menu-item class
- How to add parent element’s title to nav menu’s child?
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Add class to active element and its parent in nav menu
- display only the wp_nav_menu, which has the current-menu-item
- Hide Menu items base on capability
- Removing strip_tags not working on nav_menu_description
- How do I hide one menu item link for logged in and logged out users [closed]
- Third level navigation class
- How to add #navbar to all page links?
- How do I apply a class to custom menu items based on user roles
- add span to top level links of a wordpress menu called “main”
- Debugging – trying to add search box to menus
- wp_list_pages() but only show children on the branch you are on
- Allow users with Editor role to edit menus (without a plugin)
- From a page, is it possible to find entry’s “menu_item_parent”?
- Add active class to top-level menu items when viewing single for that post type
- Restrict control in nav-menu for specific role
- add_filter on menu items to add a menu item
- Make nav-menus.php available for editor
- how to disable default menu classes
- Insert other menus as submenus of a main menu
- Filter Menu Items by Custom User Role in a page
- list category posts under its item in menu
- Make pages visible to only logged in members
- Prevent menu from loading in a page template [duplicate]
- Insert a div before the wp_nav_menu
- How to change menu structure?
- Secondary Navigation Menudisappeared When using wp_nav_menu_items
- remove specific classes from menu items
- wp_nav_menu action/filter help
- add_filter for where statment issue
- Add a counter beside menu item label
- Add custom link on the fly to nav menu
- menu-item class missing on wordpress menu
- Filter to hook into menu items and add a custom attribute
- Possible to append class to nav menu added to widget area?
- Hiding specific navigation menus from specific roles in admin panel
- Restrict user to edit only edit a certain menu
- Modifying Woocommerce menu based on tags and categories
- Roles see different top menu (nav menu)
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Menu location switcher – example code fails
- Add Featured Image and Title to wp_nav_menu items
- Show thumbnail to category items in wp_nav_menu(), how?
- Add Class to Custom Menu Widget ul
- Users are required to login to my site. How define user.member boolean, its permissions, and conditionally display/handle behavior based on it
- Avoid changing menu query with suppress_filters => false
- Removing menu item doesn’t get removed on edit post
- Add Protocol to Custom Menus
- Hide page link in main menu from anonymous users
- Show different menus for login / logout user [closed]
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- Why is WordPress stripping anchor links from mneu item URLs?
- Problems with the navigation menu
- Add button and title on submenu WordPress
- Display a portion/ branch of the menu tree using wp_nav_menu()
- Display only page specific sub menu items using Custom Walker
- non-clickable placeholder in the menu
- Ways to give a wp_list_pages menu link specific class names?
- I want remove last after wp_nav_menu
- wp_list_pages – show pages immediately 1 level below current level
- Run a filter when a walker runs
- How do you return a menu with the menu name?
- You do not have permission to create Navigation Menus – Twenty Twenty-Two theme
- Walker class conditional based on parent menu item label or custom css class
- upload_files cap to not loggen in users – add_cap to not logged in users
- How to override menu markup?
- Recent Posts widget missing current_menu_item class
- How can I make wp_nav_menu() support tags?
- select a main navigation menu per user type from multiple main navigation menus
- (Mobile) Hamburger menu disappeared from a page (only one)
- How to add a “base” filter for all posts visible to visitors on the site?
- Hiding menu on specific pages
- sidebar navigation problem with child pages not all display.?
- How to point menu to my homepage
- How to give custom roles the capability to edit one Menu instead of every Menu
- save_post() on Menu Save
- code to add an extra selection to the menu editor
- update_post_meta breaking wp_update_nav_menu_item
- Building a menu from a large number of pages?
- How do I remove a menu from a theme?
- Custom Menu based off custom header
- Adding an additional menu in WordPress
- Database structure Menu Item