user1854512
user1854512

Reputation:

how to get nav menu list through menu name in wordpress

How do I get the nav menu list through the menu name in Wordpress?

I'm using the following code but it's showing all pages and is not using the custom nav menu name

<?php wp_page_menu('sort_column=ID&amp;sort_order=desc;');?>

Thanks for helping.

Upvotes: 1

Views: 4044

Answers (2)

Chetan
Chetan

Reputation: 102

you should register your menu in your functions.php file and add it to init.

register_nav_menu( 'header', __( 'Header Menu', 'twentyeleven' ) );

And you can display anywhere this menu as below :

wp_nav_menu( array( 'theme_location' => 'header','container' => false,'menu_id' => 'nav' ) );

Upvotes: 2

Martin
Martin

Reputation: 362

First of all,

you should really assign the menu in your functions.php file and add it to init. Something like this should do:

function register_my_menus()
{
   register_nav_menus(array( 'main-menu' => __( 'Main Menu' ) ) );
}
add_action( 'init', 'register_my_menus' );

Then in you wordpress theme you simple call it like so:

wp_nav_menu(array('menu_id' => '',
              'menu_class' => '',
              'container' => '',
              'theme_location' => 'main-menu'
));

You can fill in classes, or menu ids you need, important thing is the "main-menu" clausole displaying menu you created.

Now you just need to go to your wordpress admin > appearence > menus, select your menu from the top tab list, and assing it to theme location, on right-hand side. Where it says "Theme Locations", just select "Main Menu" from the dropdown list, and hit save.

Hope this helps.

Upvotes: 1

Related Questions