WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
you want to remove it completely from database ? – amit Aug 5 '12 at 9:14
up vote 2 down vote accepted

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.

share|improve this answer
thanks - that worked :) – OS. Aug 5 '12 at 10:50
wp_delete_nav_menu_item() is coming but thanks for this solution. – WebTechGlobal Oct 17 '15 at 8:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.