I was able to register a new menu location (it shows in the admin Appearance->Menus section. But when I call wp_nav_menu with that location, it prints nothing. If I set location =>'' then it prints it!

functions.php

//This works
add_action( 'init', 'register_my_menus' );
function register_my_menus()
{
    register_nav_menus( array( 'my_special_slug' => __( 'My Menu' )));
}

header.php

wp_nav_menu(
    array(
        'items_wrap'=> '%3$s', 
        'walker' => new MyWalker(), 
        'container'=>false, 
        'menu_class' => '', 
        'theme_location'=>'my_special_slug', //This does NOT work
        'fallback_cb'=>false 
    )
);

What am I doing wrong?

有帮助吗?

解决方案 2

It appears (please correct me if this is incorrect) that without the user going into the admin interface and turning the menu on, it cannot be found. They need to go to `Appearance->Menus->Locations" and select the menu to show for that location.

I have been unable to find a programmatic way of doing this.

其他提示

register_nav_menu takes a comma separated array.

function register_my_menus()
{
    register_nav_menu(array( 'my_special_slug', 'My Menu');
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top