Question

I am trying to retrieve of list of available menus but the array is returning empty.

function get_menus() {
    $menu_list = [];
    $wcs_menus = wp_get_nav_menus();
    foreach($wcs_menus as $m) {
        $menus_list[$m->slug] = $m->name;
      }
      return $menu_list;
}

$menus = get_menus();
var_dump($menus);
Was it helpful?

Solution

Are you missing a "s" in your variable return $menu_list;?
Your array is called $menus_list;

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top