Menu API not switching menus?

I am using the menus API, and I want to switch to a different menu, but it is holding the first one for some reason

Here is my code

Read More

in functions.php

    add_action( 'init', 'register_my_menus',10 );

function register_my_menus() {

    register_nav_menu('main-navigation', 'Main Navigation');

}

Here is the code in my theme file (header.php)

<?php 
    $args = array(
        'menu' => 'main-navigation',
        'container_id' => 'navigation',
        'fallback_cb' => 'wp_page_menu'
        );
    wp_nav_menu($args); ?> 

Related posts

Leave a Reply

1 comment

  1. _Menus are somewhat confusing around there. Try this:

    $args = array(
            'theme_location' => 'main-navigation',
            'container_id' => 'navigation',
            'fallback_cb' => 'wp_page_menu'
            );
        wp_nav_menu($args);
    

    theme_location tries to display menu that is attached to this location. menu tries to display menu by slug/id (not location of menu, but actual menu that you create in admin area).

    So you are mixing up location with menu slug, it gets confused and just serves first menu it can.

    See wp_nav_menu() documentation for full description of logic behind it.