Browse Source

Varia: fix to add logic to prevent empty menu button (#2999)

* Add check for menu items to prevent empty menu button in mobile

* Fix spacing

* variable name change

Co-authored-by: Ben Dwyer <ben@scruffian.com>
Tony Arcangelini 4 years ago
parent
commit
79a4bc7d75
1 changed files with 16 additions and 9 deletions
  1. 16 9
      varia/header.php

+ 16 - 9
varia/header.php

@@ -10,11 +10,18 @@
  * @subpackage Varia
  * @subpackage Varia
  * @since 1.0.0
  * @since 1.0.0
  */
  */
-$has_primary_nav = has_nav_menu( 'menu-1' );
-$header_classes  = 'site-header responsive-max-width';
-$header_classes .= has_custom_logo() ? ' has-logo' : '';
-$header_classes .= 1 === get_theme_mod( 'header_text', 1 ) ? ' has-title-and-tagline' : '';
-$header_classes .= $has_primary_nav ? ' has-menu' : '';
+$has_primary_nav       = has_nav_menu( 'menu-1' );
+$has_primary_nav_items = wp_nav_menu(
+	array(
+		'theme_location' => 'menu-1',
+		'fallback_cb'    => false,
+		'echo'           => false,
+	)
+);
+$header_classes        = 'site-header responsive-max-width';
+$header_classes       .= has_custom_logo() ? ' has-logo' : '';
+$header_classes       .= 1 === get_theme_mod( 'header_text', 1 ) ? ' has-title-and-tagline' : '';
+$header_classes       .= $has_primary_nav ? ' has-menu' : '';
 ?><!doctype html>
 ?><!doctype html>
 <html <?php language_attributes(); ?>>
 <html <?php language_attributes(); ?>>
 <head>
 <head>
@@ -48,7 +55,7 @@ if ( function_exists( 'wp_body_open' ) ) {
 		<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
 		<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
 			<?php get_template_part( 'template-parts/header/site', 'branding' ); ?>
 			<?php get_template_part( 'template-parts/header/site', 'branding' ); ?>
 
 
-			<?php if ( $has_primary_nav ) : ?>
+			<?php if ( $has_primary_nav && $has_primary_nav_items ) : ?>
 				<nav id="site-navigation" class="main-navigation" aria-label="<?php esc_attr_e( 'Main Navigation', 'varia' ); ?>">
 				<nav id="site-navigation" class="main-navigation" aria-label="<?php esc_attr_e( 'Main Navigation', 'varia' ); ?>">
 
 
 					<input type="checkbox" role="button" aria-haspopup="true" id="toggle" class="hide-visually">
 					<input type="checkbox" role="button" aria-haspopup="true" id="toggle" class="hide-visually">
@@ -62,9 +69,9 @@ if ( function_exists( 'wp_body_open' ) ) {
 
 
 					<?php
 					<?php
 					$main_nav_args = array(
 					$main_nav_args = array(
-						'theme_location'  => 'menu-1',
-						'menu_class'      => 'main-menu',
-						'items_wrap'      => '<ul id="%1$s" class="%2$s" aria-label="submenu">%3$s</ul>',
+						'theme_location' => 'menu-1',
+						'menu_class'     => 'main-menu',
+						'items_wrap'     => '<ul id="%1$s" class="%2$s" aria-label="submenu">%3$s</ul>',
 					);
 					);
 					if ( get_theme_mod( 'enable_side_menu' ) === 1 ) {
 					if ( get_theme_mod( 'enable_side_menu' ) === 1 ) {
 						$main_nav_args['container_class'] = 'main-menu-container';
 						$main_nav_args['container_class'] = 'main-menu-container';