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 want to create my custom nav menu using a script in a wp plugin. I'm almost there using this tutorial. All I need is the option to delete menu entries.

something like wp_delete_nav_menu_item($menuID, $itemID);

As an alternative, I could create a new menu using wp_create_nav_menu($menu_name); so I don"t have to delete the default entries of the menu I would be working with otherwise. The problem here is, that the theme gives options for the position of the menu like 'header' and I dont know how i can define a position for a newly created menu.

Hope someone can give advice so I can solve one of these issues. Thanks!

This is the code I am working with so far. I need the code for the part to delete the default entries

//Add Menu
//Get Menu ID
$mymenu = wp_get_nav_menu_object('Header');
$menuID = $mymenu->term_id;

//Check if Menu exists
if( !$mymenu ) {
    //Menu exists -> Delete the default entries
} else {
    //Menu does not exist -> Create it
    $menuID = wp_create_nav_menu('Header');

//Create new Menu Entries
//Create Parent Menu Entries
$myPage = get_page_by_title( 'Home' );
$itemData =  array(
'menu-item-object-id'   => $myPage->ID,
'menu-item-parent-id'   => 0,
'menu-item-position'    => 1,
'menu-item-object'      => 'page',
'menu-item-type'        => 'post_type',
'menu-item-status'      => 'publish'
wp_update_nav_menu_item($menuID, 0, $itemData);
share|improve this question

Here you go.

//This code will register a Location with wordpress.
//You can assign menu to this location.
function register_my_menu(){
        'header_navigation' => 'Header Navigation'

But we haven't defined any location in theme yet.

This code will be used in theme where you want your menu to get rendered.


    $menu_args = array(
        'theme_location'=> 'header_navigation', //slug from the previous code.
        'container'     =>  true,   //if you want a div around your menu.
        'menu_class'    => 'nav',   // It will add the class name of menu <ul>
share|improve this answer
I'm sorry it seems like i haven't described very well what I need. I am using an existing theme and I'm coding a plugin to create a menu as part of a setup routine. See my edit above – karunin Mar 6 '14 at 10:07

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.