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
- Filter out built-in wp_nav_menu classes but keep custom class
- How to get a different mobile menu than desktop menu in the twentytwelve child theme
- Remove navigation from header in custom page template
- Change image based on menu item id
- WordPress Add javascript:void(0); to menu link item?
- How can I put two menus in the same div?
- Add nav menu CSS class to body
- Using Shortcodes in WP-Menus in WP 3.1 (via nav_menu_objects)?
- Add id to menu items in wp_nav_menu
- how can i add css class on current page in wordpress wp_nav_menu
- How to rewrite the output of wordpress nav menu?
- Custom Links menu items include in Search Results
- Menu items suddenly are displayed all over the page [closed]
- Custom navigation structure with walker class
- CSS Classes (optional) on menu is not showing
- Plugin creation – how to add user rights?
- URL links consistent with menus?
- Strange menu behaviour wordpress admin [duplicate]
- changing the labels inside appearance -> menus for some for the fields
- Lost admin “manage_link” capability WordPress. No “Links” menu item in admin menu
- dropdown menu, with walker
- Add function to custom menu
- Custom menu with additional logic for display
- Menu item that hides when you click the previous submenu
- Putting footer links into different columns
- How to add buddypress sub-menu items to other menus
- add custom entries to menu options
- How to add drop down sub menu from database fields in the particular menu slug
- Creating a custom menu