I had the same challenge, and fixed it by adding it to the response. Example:
function get_menu() {
# Change 'menu' to your own navigation slug.
$menu_items = wp_get_nav_menu_items('menu');
foreach($menu_items as $menu_item) {
// ALTERNATIVE: $slug = get_post_field( 'post_name', $menu_item->object_id );
$slug = basename( get_permalink($menu_item->object_id) );
$menu_item->slug = $slug;
}
return $menu_items;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'myroutes', '/menu', array(
'methods' => 'GET',
'callback' => 'get_menu',
) );
} );
Related Posts:
- Does WP REST API have a built in route for calling menu?
- Reuse a custom WordPress menu on another WordPress website
- New menu is not showing in api response
- Enable identical menu on network sites
- Get Menu Items from REST API (React)
- How do I add a search box to the nav menu?
- How to get IDs for objects in menu branch?
- New post notification in wp_nav_menu
- How to use a WordPress’ existing admin icon?
- How to move parent li to end of child ul
- How to fix strange 500 Error after Editing Menu?
- Remove ‘Menus’ from Twenty Sixteen theme Customizer
- One site, 2 distinct sections: two different top nav menus?
- Can you have different menus and theme on a per-page basis?
- Custom nav walker with different output depending on depth
- Override custom menu widget
- Placing widget to menu
- container_class doesn’t seem to be working
- Get menu item slug
- Display link with current user’s username in it in Custom Menu
- Show link to add menu
- Does WordPress create mobile menus automatically?
- Change HTML structure for custom menu in sidebar
- Add custom text to menu
- Highlight current category, when using get_categories
- Menus like a CMS
- How to make a custom menu based on a category or tag?
- Hide menu item in certain condition
- Get top items number from wordpress menu
- Can I insert elements anywhere into the results of wp_nav_menu()?
- Prev / Next menu item
- wp_nav_menu() with multiple Class
- add span class and i tag inside wp_nav_menu link anchor tag
- Grey out nav buttons unless is_user_logged_in()
- burger on mobile
- How to approach this menu design?
- Trying to Create Menu in WordPress
- Hierarchical menu nesting problem with jQuery targetting
- ‘Users’ and ‘Appearance’ have disappeared from dashboard menu [closed]
- Making nav menu sticky and transparent
- Jupiter theme Mega menu option not available
- Sub Menu does not display using Nav Walker
- 2 Different Nav Menus Have Same Name in WP-Admin
- Get Menu Name inside walker
- How to add ul and li classes to nav in wordpress
- Where to implement custom walker class?
- Responsive menu gone on wordpress Responsive theme
- Creating a Mega Menu
- register_nav_menus() won’t register menus
- How can I add text to a single nav menu item?
- How to add attribute in menu code
- In the Admin Dashboard, can I choose which sections to display?
- How to change the color of a menu item [closed]
- Walker menu not displaying at all
- Where is my menu editor
- wp_nav_menu not displaying the right way
- add 3rd party link (with script) to menu item
- WordPress Menu adds an unwanted slash before anchor
- How to automatically redirect to first item of second navigation level in a multi-level menu?
- Hide an item from a menu to some users
- Locking in navigation labels before changing title?
- How to undo the last changes to a custom menu?
- How to Add support for sub-menu item description in wordpress?
- wp_nav_menu_items for one menu
- Add menu headings to WordPress sub menus
- Customise the custom menu widget
- I can’t add more pages to menu – menu delete pages
- Confused about the correct functioning on WordPress Menus
- add_menu_page does not render the expected result
- Admin Menu Hack (Left side in Dashboard)
- How to manipulate attributes of url-less dropdown item in a the custom wordpress menu?
- How do I remove this menu bar?
- Getting the WordPress custom menu titles and outputting them in a theme
- Second Level Menu
- Different Menus based on Category Page
- nav-menu-template and columns in sub menu
- current-menu-item not apllying with wp_nav_menu() on ajax
- Custom link with checkbox that adds additional word to checked menu items
- menu not showing on mobile view
- Hide a menu (navigation bar) on all posts
- Parent Menu Item Requires Two Clicks for Mobile Device
- Is it possible to have submenu outside of menu element? I dont want submenu to be a child of menu
- Bootstrap Nav Walker Sub Menu Image
- What are some of your favorite methods for creating an accessible menu?
- Product categories are mixed when creating menu
- How to get all the menu listed in Menus Created inside the Apperance Menu?
- Add a menu item to the logged in users author page?
- Add Class to Custom Menu Widget ul
- Add parent link to its submenu
- Can’t change link for navigation item
- Loading wordpress menu in an external server
- Need direction on a seemingly complex menu walker for automatically inserting a parent link li in it’s submenu ul
- Remove link from Page name in navigation bar
- Prevent Menu Shortcode From Formatting
- individual images as navigation design TwentyTen
- Setting up menus before making a template live
- Is it possible to add a superscript trademark symbol to a menu?
- Creating a Horizontal menu
- I want my homepage navbar to have different styling to the rest of my site, how can I do this?
- How to change mobile menu (toggle) icon in WordPress – Full Site Editing?