From a269ba85f77cb9c8c67fe623d2ff2501aca498ba Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sun, 16 Sep 2012 17:07:56 +0000 Subject: [PATCH] If a nav menu has no menu items, print nothing (instead of empty container markup). props obenland. fixes #21576. git-svn-id: http://core.svn.wordpress.org/trunk@21868 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu-template.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index 115889ae8a..7e790d186e 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -166,13 +166,19 @@ function wp_nav_menu( $args = array() ) { if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) $menu_items = wp_get_nav_menu_items( $menu->term_id ); - // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists + /* + * If no menu was found: + * - Fallback (if one was specified), or bail. + * + * If no menu items were found: + * - Fallback, but only if no theme location was specified. + * - Otherwise, bail. + */ if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) return call_user_func( $args->fallback_cb, (array) $args ); - // If no fallback function was specified and the menu doesn't exists, bail. - if ( !$menu || is_wp_error($menu) ) + if ( !$menu || is_wp_error( $menu ) || empty( $menu_items ) ) return false; $nav_menu = $items = '';