Some time we required to display menu item in custom as per design.

Recently i worked on one wordpress project but this projects designs are differently from other projects. Here main Problem is that display menu links in custom way.

I researched some time in Google about wp nav menu but i didn’t find solutions for display custom menu our own way. Some of people saying that use custom wp nav menu or change the core files but these not recommend by wordpress .

Finally i checked wordpress fuction refernce in Codex here i found dome of useful functions but it’s really useful fuction refernce on codex everyone should read WordPress fuction reference before any project handle

However i found wp_get_nav_menu_items fuction to get menu items in custom foreach loop

Using wp_get_nav_menu_items() fuction you will get the all menus object but you need to call menu term id in this function parameter.

For menu term id you need to call the wp_get_nav_menu_object but need to some pass parameters like menu name or menu location.

See below example to get menu object

<?php
$menu_name = 'sidebar-menu'; // Replace with your desired menu slug or location

// Get the menu location
$locations = get_nav_menu_locations();

// Check if the menu location exists
if (isset($locations[$menu_name])) {
    // Get the menu object for the specified location
    $menu = wp_get_nav_menu_object($locations[$menu_name]);
    
    // Check if the menu object exists
    if ($menu) {
        // Get menu items for the specified menu
        $menuitems = wp_get_nav_menu_items($menu->term_id, array('order' => 'DESC'));

        // Output menu items
        echo "<pre>";
        print_r($menuitems);
        echo "</pre>";
    } else {
        echo "Menu not found.";
    }
} else {
    echo "Menu location not found.";
}
?>