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')) {
register_nav_menus(
array(
'main-menu' => 'Main Menu',
'footer-menu' => 'Footer Menu',
'products-menu' => 'Products Menu',
'legal-menu' => 'Legal Menu'
));
}
}
endif;
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;
?>
ADDITIONAL INFO:
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
register_nav_menus()
call and the variouswp_nav_menu()
calls, what happens?