WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Menu Registration In Functions (3 posts)

  1. xmatter
    Member
    Posted 11 months ago #

    I have 2 sidebars (left and right)

    <?php
    
    if ( function_exists('register_sidebar') ) {
        register_sidebar(array(
    	'name'=>'Left',
            'before_widget' => '<div class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h4>',
            'after_title' => '</h4>',
        ));
    	register_sidebar(array(
    	'name'=>'Right',
            'before_widget' => '<div class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h4>',
            'after_title' => '</h4>',
        ));
    }

    I want a menu registered for each sidebar but something is incorrect. I am not sure what to place for sidebar2. Sidebar2 works for displaying the menu within the backend, but the left menu appears on the frontend in both the left and right sidebars.

    function register_my_menus() {
      register_nav_menus(
        array( 'header' => __( 'Header' ), 'main' => __( 'Main' ), 'sidebar' => __( 'Left Sidebar' ), 'sidebar2' => __( 'Right Sidebar' ), 'footer' => __( 'Footer' ))
      );
    }

    Here is the code to display menus with the sidebar-left and sidebar-right is identical

    <?php wp_nav_menu(array( 'container_class' => 'sidebar-left', 'theme_location' => 'sidebar')); ?>

    so whatever gets changed within the menu register array, i must change within the sidebar-right file to display the proper menu. Any help is appreciated!

  2. vtxyzzy
    Member
    Posted 10 months ago #

    The problem appears to be that you are using the same code to display both left and right sidebars:

    Here is the code to display menus with the sidebar-left and sidebar-right is identical

    The theme_location parameter points to the unique menu to be displayed, so it should be sidebar2 to display the 'Right Sidebar'.

  3. xmatter
    Member
    Posted 10 months ago #

    thank you, I did eventually figure it out. I wasn't sure if it was sidebar2 specifically or not.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.