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
- I only want to show links to categories that have posts in ‘publish’ state in my menu
- nav_menu_css_class add_filter is never called
- In WordPress, I want to use code to filter out one menu item (page) from displaying when I call wp_nav_menu() function
- Add div content to my already existing menu
- Is there a way to allow users with “Subscriber” user role to access media library in backend and frontend
- How to show specific admin menu to specific user role?
- Hide a menu (navigation bar) on all posts
- Hiding menu on specific pages
- Replace the page url with a menu link?
- Bootstrap Menu bar shows up a toggle in Desktop Mode
- insert an HTML element if there is a submenu only
- Add class to sub-menu from unrelated element
- Cannot collapse a responsive menu in WordPress
- Nav Menu: Theme Location not working
- Edited one page in my working menu and now all menu buttons don’t open unless I right-click and open in new tab
- Remove Link from WordPress Menu
- adding pages in underscores.me theme
- How to make WP page accessile only to specific user roles
- Is it all right to put the whole tag into template_part file?
- How to get the Page Name of the current page?
- Trying to add Newline in Menu item
- How to unlock menu editing
- open menu link (PDF) in new tab not download
- How to remove empty line space in navigation menu?
- How do you show horizontally the submenu in WordPress using the nav walker?
- How to change the navigation menu
- Is it possible to get_the_post_thumbnail (Featured Image) inside a sprintf function?
- Adding menu title to custum URL
- Need to remove the admin menu item from a be theme in wordpress