可以使用访问菜单元数据wp_get_nav_menu_object
作用
按名称:
$menu = wp_get_nav_menu_object("my mainmenu" );
按段塞:
$menu = wp_get_nav_menu_object("my-mainmenu" );
返回对象如下:
Object (
term_id => 4
name => My Menu Name
slug => my-menu-name
term_group => 0
term_taxonomy_id => 4
taxonomy => nav_menu
description =>
parent => 0
count => 6
)
要显示名称,请执行以下操作:
echo $menu->name;