How can I create a new WordPress menu programmatically and assign the menu item to the new menu
You can use WordPress native function wp_create_nav_menu to create a new menu and using wp_update_nav_menu_item to assign the menu items
$menuname = "New Menu"; $menu_exists = wp_get_nav_menu_object( $menuname ); if( !$menu_exists){ $menu_id = wp_create_nav_menu($menuname); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Home'), 'menu-item-classes' => 'home', 'menu-item-url' => home_url( '/' ), 'menu-item-status' => 'publish')); }