wp_nav_menu not working wordpress

I am creating a theme for my wordpress blog, I am struct on the code to display custom menus

in my functions.php I have wrote:

Read More
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

Related posts

Leave a Reply

2 comments

  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 of

    if ( 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.