I’m building a site’s navigation bar programmatically, using the following code:
wp_update_nav_menu_item($menu->term_id, 0, array( 'menu-item-title' => $page_data->post_title, 'menu-item-classes' => 'main', 'menu-item-url' => '/', 'menu-item-status' => 'publish'));
this adds menu items to my navigation bar and works well. I use this to pre-populate a number of menu items when site is created.
The question is how do I delete a menu item from the nav menu? (for example if user wants different menu items in the nav bar).
I know that I can use exclude, but that doesn’t seem like the right solution since I don’t want to constantly manage the exclude list based on user changes.
another question: how do I change menu order via code?
As the menu Items are stored as a post type. Not sure but I think we can use
wp_delete_post() to programmatically remove it. That will completely remove the menu item from database, So you cant ever have that menu item again.