문제

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