Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow my theme to support multiple menus in wordpress

Tags:

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?

like image 795
shivani Avatar asked Feb 12 '23 20:02

shivani


1 Answers

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'));?>
like image 101
Rohil_PHPBeginner Avatar answered Mar 02 '23 00:03

Rohil_PHPBeginner