wp_get_nav_menu_items() showing not defined with all menu slugs
-
I am attempting to use the little snippet of code on the codex page for wp_get_nav_menu_items() but every time I attempt to run the code with the menus on my test site it always comes up “menu-blah not defined”
Code:
$menu_name = 'short-menu'; if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) { $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menu_items = wp_get_nav_menu_items($menu->term_id); $menu_list = '<ul id="menu-' . $menu_name . '">'; foreach ( (array) $menu_items as $key => $menu_item ) { $title = $menu_item->title; $url = $menu_item->url; $menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>'; } $menu_list .= '</ul>'; } else { $menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>'; } // $menu_list now ready to output echo $menu_list;
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘wp_get_nav_menu_items() showing not defined with all menu slugs’ is closed to new replies.