Try this :
$menu = get_term( $locations[$theme_location], 'nav_menu' );
$menu_items = wp_get_nav_menu_items($menu->term_id);
foreach( $menu_items as $menu_item ) {
$link = $menu_item->url;
$title = $menu_item->title;
$slug = basename($menu_item->url);
}
Pass the whole permalink to the basename
function, which will automatically process the URL and give us only the slug.
Related Posts:
- Adding Custom Link anchors in the top menu that points to specific sections of the site home page
- Redirect to another page using contact form 7? [closed]
- How to display page ids as page slug names?
- How to assign a default/priority taxonomy to be shown in url in case two taxonomy items are selected
- Remove wrapping div and ul from output of wp_nav_menu
- get post author id outside loop
- Custom Walker: how to get ID in function start_lvl
- Add custom html to last sub-menu item
- Natural URL Design and static front page
- wp_nav_menu() custom container and container_id
- global menus made from master site’s custom menus wpmu network
- Editing the Number at the end of Page URLs / Editing Page Slugs
- How to build custom WP admin with custom URLs
- Create subpage /user/ or /my-profile/ like /author/ with additional query like /user/user123
- Change default status and replace the icon for an hamburger menu
- simple expandable vertical menu, java script problem
- Create a Custom menu item fetched by Product Categories and Sub Categories
- how to flush custom author rewrite rule
- Passing page url into a custom field via the Press-This bookmarklet
- Add filename to attachment page url
- How to extend nav-menu-item-control data in Appearance > Customize?
- add_rewrite_rule won’t work
- Remove Author Slug & Replace With Username
- Why ids in urls don’t work but slugs do?
- How can I get the intended URL in a 404?
- Creating Search Engine Friendly URL’s with Word Press
- Adding all sub-pages to the menu manager
- add JS to multiple plugin admin pages
- pass user id in slug and get user information
- Programmatically (PHP) get the nr. of items in the primary navigation menu
- WordPress slugs and 404 handling takes preference over folders in site root?
- How to create left and right menu with logo center in a custom theme?
- Add clickable arrows to parent menu items with children elements e.g. with
- How Do I Remove The Right Hand Block On The Main Header?
- How to change the category url jusy show /category/%category_id% in wordpress?
- Adding posts to custom menu [closed]
- How to wrap the list with custom class using wp_nav_menu?
- Alphabetical Custom Menu
- change url for static files in /wp-admin with a cdn url
- Sub menu indicator that links to sub menu
- Navigation label for page in custom theme
- how to display a specific wordpress menu?
- Create a url structure for my blogs based on categories and sub-cats
- Sticky menu for WP custom menubars
- Don’t change Custom Post Type slug to unique value
- Get wordpress taxonomy slug name(s) to use as div class
- Stop Expansion of Top Level Menu in the WordPress Admin Sidebar
- Insert menu with a custom walker into page / post body using shortcode?
- Implement a Walker with custom object rather than WordPress database object
- How can I tag a menu item as visited for each unique user?
- How do I create a root link in wordpress to a PDF file?
- How can i create menu like in the example?
- WordPress custom dropdown listings
- How to request container_class from wp_nav_menu
- Menu not appearing in custom theme
- Many Rewrite Parameters/Rules
- How can i display custom menu in sidebar?
- How to have multiple WordPress Menus
- How to add active state to the navigation links?
- Missing current_page_item in custom menu
- WordPress menu: How to make www.link.com/#name never contain current_page_item class?
- Customize Widget Navigation
- Custom menu not showing even though it shows as being registered?
- query variables for custom taxonomies
- How to get Previous Visited Page Information
- Custom CSS Nav Menu Style Not Being Applied
- If Term Name Exists, Append a Unique ID to Slug
- Get post slug and match with menu item slug to change css
- Current menu item highlights wrong
- Adding a custom field to a slug
- Add producthunt badge to wordpress menu
- Woocommerce custom “My Account” Tab – Add Save button
- Swap out a page that is a parent to a many many pages
- Adding a drop-down (select tag) option under Menu Settings in WordPress Admin
- How to add a template – so that i can choose a different menu for some pages
- URL issue after setting up Custom Structure in Settings >> Permalinks
- clickable toggle menu, help
- Replace an URL with an new URL which has a “?” in it
- Help needed creating a custom Hamburger menu in header
- Menu selection for header
- How to create a custom menu for specific user
- How to customize WordPress vertical menu?
- Creating a dynamic URL for an external link inside content
- remove or hide Link Relationship (XFN) form Menus tab
- My connecting URL form in html to PHP does not work
- User WordPress menu in custom page
- Adding images to anchors in the list created and fetched with wp_nav_menu
- how to hard link to the posts page?
- Page Permalinks: Custom URLs
- How do I display entries in the top menu based on conditions selected in the sidebar menu?
- How to work around the bug which prevents custom menus from being deleted?
- Class .current-menu-item in custom menu Walker
- Changing starting number of User ID
- How to keep the /blog slug even in single post slug
- menu customization
- Pass query param to custom page
- How to move menu next to left of the search box?
- Custom CSS File wont work on second Page
- removing extra mobile menu from the header
- Custom Menu (only showing direct cildren) ACF not showing