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 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


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

Browse other questions tagged or ask your own question.