If you want to create a custom menu by code and assign it to a menu location in WordPress, then this question and answer for you.
Add the below code at the end of your theme’s functions.php file or you can also add the below code inside your site-specific plugin.
//give your menu a name
$name = 'theme default menu';
//create the menu
$menu_id = wp_create_nav_menu($name);
//then get the menu object by its name
$menu = get_term_by( 'name', $name, 'nav_menu' );
//then add the actuall link/ menu item and you do this for each item you want to add
wp_update_nav_menu_item($menu->term_id, 0, array(
'menu-item-title' => __('Home'),
'menu-item-classes' => 'home',
'menu-item-url' => home_url( '/' ),
'menu-item-status' => 'publish'));
// you add as many items ass you need with wp_update_nav_menu_item()
//then you set the wanted theme location
$locations = get_theme_mod('nav_menu_locations');
$locations['LOCATION_NAME'] = $menu->term_id;
set_theme_mod( 'nav_menu_locations', $locations );
That’s all, I hope this helped you!
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.