shivani
shivani

Reputation: 756

How to allow my theme to support multiple menus in wordpress

I am developing a site in Wordpress. I am using a theme named Moesia. While customizing the the theme according to my website needs, i found that the theme only supports one menu which is the main menu at the Top Right.

I want to add another menu which will only be visible inside a page. I have tried to add custom menu to a page, the issue that when I click on a menu item the whole page refreshes and the menu goes away. I want the menu to stay on that page and a click on the menu item should display the content adjacent to the menu.

I am absolutely new to this technology.

How can I achieve this?

Upvotes: 4

Views: 12284

Answers (1)

Rohil_PHPBeginner
Rohil_PHPBeginner

Reputation: 6080

Add the following to your functions.php file. The 2 menus are the “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 to your 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'));?>

Upvotes: 8

Related Questions