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 am programmatically generating a navigation menu with the following....

add_action( 'init', 'register_navmenus' );
function register_navmenus() {

// Check if Top menu exists and make it if not
if ( !is_nav_menu( 'Navigation' )) {
    $menu_id = wp_create_nav_menu( 'Navigation' );

    $menu1 = array('menu-item-title' => 'Home','menu-item-object' => 'page','menu-item-object-id' => get_page_by_path('home')->ID,'menu-item-type' => 'post_type','menu-item-status' => 'publish');

    $menu2 = array('menu-item-title' => 'Register','menu-item-object' => 'page','menu-item-object-id' => get_page_by_path('register')->ID,'menu-item-type' => 'post_type','menu-item-status' => 'publish');

    $menu3 = array('menu-item-title' => 'Login','menu-item-object' => 'page','menu-item-object-id' => get_page_by_path('login')->ID,'menu-item-type' => 'post_type','menu-item-status' => 'publish');

    wp_update_nav_menu_item( $menu_id, 0, $menu1 );
    wp_update_nav_menu_item( $menu_id, 0, $menu2 );
    wp_update_nav_menu_item( $menu_id, 0, $menu3 );
}       
}

This all works correctly apart from Login, its not created. Is the 'login' slug already being used by the system or something similar?

NOTE If I change the line to...

    $menu3 = array('menu-item-title' => 'Login','menu-item-object' => 'page','menu-item-object-id' => get_page_by_path('login1')->ID,'menu-item-type' => 'post_type','menu-item-status' => 'publish');

Then the page does get generated but obviously doesnt link as the slug is incorrect

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.