Easily Learn Code

Fixed Error -get_nav_menu_locations not working


Easily Solve the get_nav_menu_locations not working Problem

Problem is get_nav_menu_location() function return false

var_dump( wp_get_nav_menu_items('swastu-header-menu') );             // bool(false)

Register your menu or menus following methods or function.

function RegisterMenus(){
    register_nav_menus(
        [
        'swastu-header-menu'=> esc_html__('Header Menu','swastu'),
        'swastu-footer-menu'=> esc_html__('Footer Menu','swastu'),
        ]
    );
}

function get_menu_id($location){


    $locations = get_nav_menu_locations();
    
    $menu_id = $locations[$location];


    return !empty($menu_id)? $menu_id : '';
}


After registed menus you can see the menu category option (menu) on Appearance.

click the menu.

Create the Menu Name Header Menu or Primary menu anything.

Or you can see this create new menu option then click and add new menu

After doing this process you need to assign the created menu with the registered menu or display location, Follow the image.

Great, it’s done

Still have your Problem?, mention on the comment.

Leave a Reply