Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got this code below working to create a default menu. I was wondering how I would create sub-items/subpages...

// Check if the menu exists
$menu_exists = wp_get_nav_menu_object('Main Menu');

// If it doesn't exist, let's create it.
if( !$menu_exists){
    $menu_id = wp_create_nav_menu('Main Menu');


  // Set up default menu items

    wp_update_nav_menu_item($menu_id, 0, array(
        'menu-item-title' =>  __('Home'),
        'menu-item-type' => 'post_type',
        'menu-item-object' => 'page',
        'menu-item-url' => get_permalink($pageId),
        'menu-item-status' => 'publish'));
}

[edit] Sorry all! I forgot to mention that I was implementing this menu on every installation of a Wordpress multisite. So when you do a new installation this default menu would already be in place.

share|improve this question
1  
What happens when you use the Custom Nav Menu feature as it's intended, instead of trying to force a square peg into a round hole? –  Chip Bennett Oct 21 '13 at 15:12
    
@ChipBennett Sorry, I was hoping to this on a Wordpress Multisite installation. –  Laura Oct 23 '13 at 2:54
    
What does the use of Multisite have to do with wp_nav_menu()? –  Chip Bennett Oct 23 '13 at 11:32
    
Whenever you do a new installation of a multisite, the theme comes with a pre-existing menu –  Laura Oct 23 '13 at 22:19

2 Answers 2

I was also doing the same thing check out this question Hope this will help you .

Menu page Exists or not

share|improve this answer

Are you using one of the default themes or something similar? You normally organise sub-pages by setting the 'Parent' attribute in the 'Edit Page' page. You'll probably find that the default menu will then show these correctly.

Alternatively, you can always edit the structure and order of a menu through the WP dashboard...Appearance...Menus. You drag and drop pages or categories into the menu as required. If you drag a page to the right inside the structure box, it will make it a sub-item in the menu.

share|improve this answer
    
Sorry, I was hoping to this on a Wordpress Multisite installation. –  Laura Oct 23 '13 at 2:53
    
Apologies, I didn't properly look at what you were doing! –  cfgm Oct 26 '13 at 9:17

Your Answer

 
discard

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.