2

How to get nav menu list through menu name in WordPress

I'm using this code by this code but showing all pages not working with custom nav menu name

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

1 Answer 1

2

I think you're looking for the wp_nav_menu() function, which deals with the navigation menus that you create in the WordPress admin (Appearance > Menus)

You can call it like this:

<?php wp_nav_menu( array( 'menu' => 'Header Menu' ) ); ?>

Where Header Menu is the name of the menu you want to print. There are other parameters available.

3
  • Did my solution work for you, @javeednizar?
    – shea
    Commented Dec 18, 2012 at 7:06
  • I know this is kind of old, but that will return a 500 error (as of the date of this comment). You'll need to wrap the key => values inside an array: wp_nav_menu( array('menu' => 'menu_name') );
    – stinkysGTI
    Commented May 3, 2019 at 4:51
  • @stinkysGTI good catch, thanks. Not sure how it's been wrong for so long.
    – shea
    Commented May 3, 2019 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.