最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Rename the label on a menu location which is already defined?

programmeradmin8浏览0评论

I have a menu location defined by a theme, I'd like to change the label from Header Menu to something else (but keeping all it's other settings as is), I can't find any suitable filters to do this within WordPress - is this possible?

I have a menu location defined by a theme, I'd like to change the label from Header Menu to something else (but keeping all it's other settings as is), I can't find any suitable filters to do this within WordPress - is this possible?

Share Improve this question asked Feb 22, 2020 at 10:01 bigdaveygeorgebigdaveygeorge 2074 silver badges12 bronze badges 3
  • The label is defined by the theme, not by WordPress. – Max Yudin Commented Feb 22, 2020 at 14:38
  • Yes, the label is defined by the theme with no filter, therefore the question is whether there are any hooks/filters within WordPress which reads those definitions and to then manipulate the label at that point to give the desired result. @MaxYudin – bigdaveygeorge Commented Feb 22, 2020 at 17:28
  • There's no hook for registered menus. – Jacob Peattie Commented Mar 4, 2020 at 1:29
Add a comment  | 

1 Answer 1

Reset to default 1

You are right there is no filter for this, you would have to hack the global instead, in this case $_wp_registered_nav_menus:

add_action('after_setup_theme', 'custom_menu_location_label');
function custom_menu_location_label() {
    global $_wp_registered_nav_menus;
    $find = __('Header Menu'); $replace = __('Something Else');
    foreach ($_wp_registered_nav_menus as $location => $description) {
        if ($find == $description) {
            $_wp_registered_nav_menus[$location] = $replace;
        }
    }
}
发布评论

评论列表(0)

  1. 暂无评论