Skip to content

Instantly share code, notes, and snippets.

@matthijs166
Created December 21, 2017 12:31
Show Gist options
  • Save matthijs166/be2fab83f2ea4d1e259f66905ba50cef to your computer and use it in GitHub Desktop.
Save matthijs166/be2fab83f2ea4d1e259f66905ba50cef to your computer and use it in GitHub Desktop.
Wordpress get all nav items and sub nav item by registerd slug in the code uing register_nav_menu
//get menu items by code registerd slug
function get_menu_items_by_registered_slug($menu_slug) {
$menu_items = array();
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_slug ] ) ) {
$menu = get_term( $locations[ $menu_slug ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
}
return $menu_items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment