Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.