Support » Developing with WordPress » Trying to include second WordPress menu in mobile version of site

  • I’m working on the redesign of a website which is already mobile responsive. At the moment it uses one menu in the top right corner. We want to split the menu so the services section sits in another menu below the header and above the content.

    This was easy to do but a problem arose in the mobile version because the code currently only requests one menu: ‘primary’.

    Here’s the code:

    <?php $primarymenu = array(
                            'theme_location'  => 'primary',
                            'menu'            => '',
                            'container'       => '',
                            'container_class' => '',
                            'container_id'    => '',
                            'menu_class'      => '',
                            'menu_id'         => '',
                            'echo'            => true,
                            'fallback_cb'     => 'wp_page_menu',
                            'before'          => '',
                            'after'           => '',
                            'link_before'     => '',
                            'link_after'      => '',
                            'items_wrap'      => '<ul>%3$s</ul>',
                            'depth'           => 0,
                            'walker'          => ''
                          if ( has_nav_menu( 'primary' ) ) {
                            wp_nav_menu( $primarymenu );

    My question is – what changes do I need to make to this code so it includes and displays the new/second WordPress menu as well?


    • This topic was modified 5 months, 1 week ago by SteDuck.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @steduck

    You will need to register multiple menus in your functions.php file using the function register_nav_menus(). Here is an article from the WP codex to help you with this theme functionality. Please have a look at the article (link below).

    The function register_nav_menus() “registers multiple custom navigation menus in the new custom menu editor of WordPress 3.0. This allows for the creation of custom menus in the dashboard for use in your theme.”

    Hope this helps you solve the issue you are experiencing.

    If you don’t want the user interface, you don’t have to register the menu location. You can just output the menu you want, where you want it, but it won’t be the one that is registered as ‘primary’.
    The arguments you set in your code are a bit odd. Since you have an if statement checking for the primary menu, there is no need for the fallback. And if you don’t put any class or ID on it, it makes it more difficult to style.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.