0

I am wondering where I can create menus without using the admin panel, or if it is a waste of time. In admin you can go to

Appearance => Menus

Where you can select a number of pages to add to the menu, select if it is the primary navigation in the theme etc etc

I assume these menus are simply stored in the wp database (since they contain links to wp pages, also stored in the database?)

If they are indeed stored in the database as opposed to templates, is what I am asking a waste of time? I assume I would have to look up the page id of the pages I would want to link to and these may be hardcoded?

3

Try this link may helpful

http://codex.wordpress.org/Function_Reference/wp_create_nav_menu

// Check if the menu exists
$menu_exists = wp_get_nav_menu_object( $menu_name );

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

    // Set up default menu items
    wp_update_nav_menu_item($menu_id, 0, array(
        'menu-item-title' =>  __('Home'),
        'menu-item-classes' => 'home',
        'menu-item-url' => home_url( '/' ), 
        'menu-item-status' => 'publish'));

    wp_update_nav_menu_item($menu_id, 0, array(
        'menu-item-title' =>  __('Custom Page'),
        'menu-item-url' => home_url( '/custom/' ), 
        'menu-item-status' => 'publish'));

}

Hope it may help :)

1

You can create menus using register_nav_menus()

Using the example in the above link, you world simply add the following to your themes functions.php file

register_nav_menus( array(
    'pluginbuddy_mobile' => 'PluginBuddy Mobile Navigation Menu',
    'footer_menu' => 'My Custom Footer Menu',
) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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