• Resolved jj11

    (@jj11)


    Could someone who knows php PLEASE look at this code and tell me why the footer menus are NOT calling the pages from the menu labelled “main” in the Appearance / Menus page – instead they are listing every page that I have in my Pages section whether or not they are listed in Appearance Menus.

    In my functions file, I have

    <?phpif ( function_exists(‘register_sidebar’) )
    register_sidebar(array( ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
    ‘after_widget’ => ”, ‘before_title’ => ‘<h2 class=”widgettitle”>’,
    ‘after_title’ => ‘</h2>’,
    ));

    function register_my_menus() {
    register_nav_menus
    (array
    (‘extra-menu’ => __( ‘main’ )));}
    add_action( ‘init’, ‘register_my_menus’ );
    ?>

    In my footer file, I have:

    • <?php wp_nav_menu( array( ‘theme_location’ => ‘main’ )); ?>

    I’ve called my menu “main” on the Appearance Menus page, in the functions file and also in the footer file.

Viewing 3 replies - 1 through 3 (of 3 total)
  • // THIS THEME USES wp_nav_menu() IN TWO LOCATION FOR CUSTOM MENU.
    if ( function_exists( 'register_nav_menus' ) ) {
    	$args = array(
    	  'main' => __( 'Primary Header Nav' ),
    	  'secondary' => __( 'My Custom Footer Menu' )
    	);
    	register_nav_menus( $args );
    }

    use this to register as many menus as you want. You’ll notice as an example here, there are two menus. main, and secondary. Main and secondary are the theme locations, how you would call them. The second bit is the description of the menu. You can delete lines, add lines, etc, to have as many menus as you like

    Thread Starter jj11

    (@jj11)

    Rev. Voodoo – Many thanks indeed for you help. Have now fixed this.

    Thanks again!!

    Ok!

    Back to basics, looking at your code the ‘main’ location is registered and the code in the footer should return it.

    Setup
    Admin > Appearance > Menus
    Have you Created a new menu list for the footer ?
    Have you assigned this menu to the ‘main’ Theme Location?

    If you have not done this then all pages get returned, to make it optional change in the footer php.

    <?php wp_nav_menu( array( 'theme_location' => 'main') ); ?>
    To
    <?php wp_nav_menu( array( 'theme_location' => 'main', 'fallback_cb' => '' ) ); ?>

    The call to the fallback will now not load the pages, and only load a menu if you have Created a menu and Assigned a menu to the ‘Theme Location’.

    HTH

    David

    EDIT: Resolved while I was adding the reply, and the theme location in the OP’s code would have been ‘extra-menu’ and not ‘main’!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calling an Appearance menu’ is closed to new replies.