Custom nav menu is created with default pages, but not hooked to theme’s custom menu location

wp_create_nav_menu() function accepts the menu name and not the menu location.
and as for wp_update_menu_item() well its for items and not the menu itself.
After digging in the code i found out that “assignment” of ‘theme location’ to a menu is not done using of the nav_menu API in WordPress but with theme options so:

//first get the current theme
$theme = get_current_theme();
//get theme's mods
$mods = get_option("mods_$theme");
//update mods with menu id at theme location
$mods['nav_menu_locations']['header-menu'] = $menu_id;
update_option("mods_$theme", $mods);

hope this helps 🙂

Leave a Comment