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?
1 Answer
Reset to default 3get_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);