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

plugins - How to get menu location in wp_update_nav_menu hook

programmeradmin1浏览0评论

I want to get the menu location in the wp_update_nav_menu (during menu save action)

  add_action('wp_update_nav_menu', function ($id, $data = NULL)
    {
        error_log( var_export($data, true) );

    }, 10, 2);

However, the data only contains the menu-name, so how can I get the menu location?

I want to get the menu location in the wp_update_nav_menu (during menu save action)

  add_action('wp_update_nav_menu', function ($id, $data = NULL)
    {
        error_log( var_export($data, true) );

    }, 10, 2);

However, the data only contains the menu-name, so how can I get the menu location?

Share Improve this question asked Jun 8, 2014 at 17:20 YogaYoga 9192 gold badges20 silver badges39 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

get_nav_menu_locations will give you menu IDs keyed by location which should correspond to the $id also passed with wp_update_nav_menu.

add_action('wp_update_nav_menu', function ($id, $data = NULL){

    foreach( get_nav_menu_locations() as $location => $menu_id ){
        if( $id == $menu_id ){
            echo 'location is ' . $location;
        }
    }

}, 10, 2);
发布评论

评论列表(0)

  1. 暂无评论