【问题标题】:How to display the menu name of a menu in wordpress如何在wordpress中显示菜单的菜单名称
【发布时间】:2015-09-18 09:01:59
【问题描述】:

我创建了一个名为 "alggemeen" 的菜单,并向其中添加了一些项目。

我已使用 'footer-menu' 将菜单分配给主题位置 Footer menu。

现在我知道如何显示菜单的内容以及 menu_location。但我想在我的网站上显示 wordpress 管理员将在后台为菜单提供的名称。

我想回显已分配给主题位置为'Footer Menu(slug = 'footer-menu')' 的菜单的菜单名称。

所以如上图所示目前algemeen是分配给Footer Menu的菜单,所以我的前端应该回显algemeen。

【问题讨论】:

标签: wordpress


【解决方案1】:

试试这个代码:

$menu_location = 'header';

$menu_locations = get_nav_menu_locations();

$menu_object = (isset($menu_locations[$menu_location]) ? wp_get_nav_menu_object($menu_locations[$menu_location]) : null);

$menu_name = (isset($menu_object->name) ? $menu_object->name : '');

echo esc_html($menu_name);

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 2020-12-13
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多