Nav Menu Selector
A dropdown that lists all navigation menus currently assigned to a menu location in WordPress. Useful when editors need to swap out which menu appears in a widget, a custom header region, or a Flexible Content component.
Settings
| Setting | Default | Options | Description |
|---|---|---|---|
| Return Format | id | id · slug · name | Controls what get_field() returns. |
Return values
return_format: 'id'
Returns the menu ID as an integer.
$menu_id = get_field('footer_nav');
// 3
return_format: 'slug'
Returns the menu slug string.
$menu_slug = get_field('footer_nav');
// "footer-menu"
return_format: 'name'
Returns the menu name as shown in the WordPress admin.
$menu_name = get_field('footer_nav');
// "Footer Menu"
Usage
Rendering the selected menu
$menu_id = get_field('sidebar_nav');
if ($menu_id) {
wp_nav_menu([
'menu' => $menu_id,
'container' => 'nav',
'container_class' => 'sidebar-nav',
'menu_class' => 'sidebar-nav__list',
'depth' => 2,
]);
}
Using the slug format
$menu_slug = get_field('footer_links');
if ($menu_slug) {
wp_nav_menu([
'menu' => $menu_slug,
'depth' => 1,
]);
}
Fallback to a default menu
$menu_id = get_field('custom_nav') ?: wp_get_nav_menu_object('Primary Menu')?->term_id;
if ($menu_id) {
wp_nav_menu(['menu' => $menu_id]);
}
Getting menu items without rendering
$menu_id = get_field('mega_menu');
if ($menu_id) {
$items = wp_get_nav_menu_items($menu_id);
foreach ($items as $item) {
echo '<a href="' . esc_url($item->url) . '">' . esc_html($item->title) . '</a>';
}
}