As a follow on from my last unresolved query regarding menus, the problem has extended even further.

My menus are not printing anywhere in the code.

I am registering the menu functions.php:

add_action( 'after_setup_theme', 'your_newtheme_setup' );

if ( ! function_exists( 'your_newtheme_setup' ) ) :

    function your_newtheme_setup() {

        if (function_exists('register_nav_menu')) {
                    'main-menu' => 'Main Menu',
                    'footer-menu' => 'Footer Menu',
                    'products-menu' => 'Products Menu',
                    'legal-menu' => 'Legal Menu'


I then call the menu in header.php:

wp_nav_menu( array( 'theme_location' => 'main-menu' ) ); 

This results in nothing being printed!

I am also trying to include the menu in the sidebar_footer.php where I have created a widget using the 'Custom Menu' widget and I've created 3 custom menus: footer-menu, products-menu & legal-menu and again, none of the menus are being printed!

The widget at least prints the heading of the widget but the menu itself produces nothing!

This is clearly an issue with all menus in my theme that I cannot seem to resolve!

IMPORTANT NOTE: I have built the main-menu manually using the following code which I found in the wordpress docs:

            $menu_name = 'main-menu';

            if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {

                $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );

                $menu_items = wp_get_nav_menu_items($menu->term_id);

                $menu_list = '<ul id="' . $menu_name . '">';

                foreach ( (array) $menu_items as $key => $menu_item ) {
                    $title = $menu_item->title;
                    $url = $menu_item->url;
                    $menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>';
                $menu_list .= '</ul>';
            } else {
                $menu_list = '<ul><li>No Menu</li></ul>';
            echo $menu_list;


I've done some debugging in the function wp_nav_menu() and found that the menu items disappear during this call:

$items = apply_filters( 'wp_nav_menu_items', $items, $args );

in line: 223 (or thereabouts) in the file: nav-menu-template.php

  • Can you explain what and why you've done everything from IMPORTANT NOTE and after? If you remove all menu-related code other than the register_nav_menus() call and the various wp_nav_menu() calls, what happens? Mar 3, 2012 at 1:18
  • Nothing happens - I tried accessing individual elements instead of the entire wp_nav_menu() to see if I could print something and it worked - there are menu items priting but wp_nav_menu just prints null... Mar 3, 2012 at 6:13

1 Answer 1


it turns out that after copying some code from another post (http://stackoverflow.com/questions/9439877/adding-menu-items-in-wordpress) for a filter in functions.php to add the search bar in the nav menu, when it wasn't matching the menu, it was returning nothing (i.e erasing the $items) I stupidly copied this code in without testing... and it was the problem all along!

Your Answer

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

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