如何在数组中获取我的菜单?
使用wp_nav_menu ( );
,我将获得带有 HTML 的列表,但我不想要 HTML 标签。我只想要数据。
我找到了这个,但是这条线是什么 - $menu_name = 'custom_menu_slug';
?
$menu_name = 'custom_menu_slug'; // Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_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);
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
}
}
有任何想法吗?