I would like a nav menu with icons and description in a mega-menu. So I use ACF to add icons and description, and wp_nav_menu_objects to inject them into the menu.
The trouble is, it injects them into every menu. I only want to target some menus. I tried registering some locations and targetting them, but the location is always empty:
function ds_custom_menu_location() {
register_nav_menus(
array(
'quick-menu' => __( 'Front Page Help Menu' ),
'mega' => __( 'Mega Menu' )
)
);
}
add_action( 'after_setup_theme', 'ds_custom_menu_location' );
function ds_wp_nav_menu_objects( $items, $args ) {
if($args->theme_location !== "mega") return $items;
foreach( $items as &$item ) {
$icon = get_field('mmenu_icon', $item);
$menudesc = get_field('category_menu_desc', $item);
if( $icon && $menudesc ) {
$item->title = '<div class="mmenu-icon bricks-color-dark"><i class="fa fa-'.$icon.'"></i></div><div class="mmenu-texts">' . $item->title;
$item->title .= '<div class="mmenu-desc bricks-color-dark">' . $menudesc . '</div></div>';
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'ds_wp_nav_menu_objects', 10, 2);
I only half understand what I’m doing, and wondered if it’s necessary to instantiate the menu with its location? Which I can’t do in native Bricks? Or if I’m missing something.
Why is $args->theme_location always empty?
Thanks in advance.