How to enable my theme to support multiple menus in wordpress

I am developing a website in Wordpress. I am using the Moesia theme. While customizing the theme to suit the requirements of my website, I found that the theme only supports one menu, which is the main menu in the top right corner.

I want to add another menu that will only appear inside the page. I tried to add a custom menu to the page, the problem is when I click on the menu item the whole page refreshes and the menu goes away. I want the menu to stay on this page and clicking on the menu item should display content adjacent to the menu.

I am completely unfamiliar with this technology.

How can I achieve this?

+3


source to share


1 answer


Add to your functions.php

file. The 2 menus are "Primary" and "Secondary" menus.

//Register Navigations
add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
   register_nav_menus(
        array(
            'primary-menu' => __( 'Primary Menu' ),
            'secondary-menu' => __( 'Secondary Menu' )
        )
    );
}

      



To add them to your site, you need to add the following WordPress template files (most likely your header.php and footer.php files ).

<?php wp_nav_menu (array('theme_location' => 'primary-menu','menu_class' => 'nav'));?>
<?php wp_nav_menu (array('theme_location' => 'secondary-menu','menu_class' => 'nav'));?>

      

+7


source







All Articles