wp_nav_menu not working wordpress




Geniuswp show

Summary: 1 I am creating a theme for my wordpress blog, I am struct on the code to display custom menusin my functions.php I have wrote:function register_my_menus(){register_nav_menus( array('menu-1' => __('Primary Menu'), ));}add_action('init', 'register_my_menus');this is my header.php if ( has_nav_menu( $location ) ) { wp_nav_menu(array( 'theme_location' => 'menu-1')); }the problem is that when I am setting a menu from wordpress to Primary Menu, no menu is displaying and also the content after menu is not displaying, please help me where I am wrong php wordpress Improve this question asked Oct 8, 2013 at 8:07 Mandeep SinghMandeep Singh10111 silver badge88 bronze badges 1 register_nav_menus is used for multiple menus, use register_nav_menu–Vidya L Oct 8, 2013 at 9:49 Add a comment | 2 Answers Active Oldest Votes 1 You've used the has_nav_menu() command, by the looks of it, copy/pasted from the Codex, without giving it a parameter. Try this:Instead ofif ( has_nav_menu( $location ) ) { wp_nav_menu(array( 'theme_location' => 'menu-1'));}This:if ( has_nav_menu( 'menu-1' ) ) { wp_nav_menu(array( 'theme_location' => 'menu-1'));}Then, provided you've actually made a menu for the location in the admin panel, and assigned it to this location, it should work as far as I can see. Improve this answer answered Oct 8, 2013 at 9:57 Owen C. JonesOwen C. Jones1,31511 gold badge1010 silver badges1313 bronze badges 2 I noticed that, this problem is with every theme, so I need to look other code to solve the problem–Mandeep Singh Oct 8, 2013 at 11:06 Apologies for the potentially silly question but, is the menu empty or unassigned?–Owen C. Jones Oct 10, 2013 at 12:43 Add a comment | 1 Hi mandeep singh did you assign your menu to the Primary Menu in the wordpress admin pannel Improve this answer answered Oct 8, 2013 at 11:27 SreekanthSreekanth1344 bronze badges 1 Thank you. In my case it was so weird, I had to click on the 'add menu' button in the backend. Even though the menu was already defined including menu items. Afterwards I could select 'Primary'. Now the theme filters like 'wp_nav_menu' suddenly work as expected.–Floris Aug 24, 2017 at 12:23 Add a comment | Not the answer you're looking for? Browse other questions tagged php wordpress or ask your own question. You are listening to the topic about "wp_nav_menu not working wordpress", if you want to read the full article, please visit https://geniuswp.com or the link in the description.