How can I fix my menu on the blog page?

Please help me.

The menu on my blog page will not display correctly.

I’m using primary menu on home page and blog menu on blog page (and posts). Menu works well on all pages EXCEPT the blog page ( /blog)

This is the code I have used after line 31 in /x-child/framework/views/global/_navbar.php :

<a href="#" class="x-btn-navbar collapsed" data-toggle="collapse" data-target=".x-nav-wrap.mobile">
			  <i class="x-icon-bars" data-x-icon="&#xf0c9;"></i>
			  <span class="visually-hidden"><?php _e( 'Navigation', '__x__' ); ?></span>
			</a>
			
			<nav class="x-nav-wrap desktop" role="navigation">
			   <?php
					wp_nav_menu( array(
					  'menu' => 'Blog Menu',
					  'container'      => false,
					  'menu_class'     => 'x-nav sf-menu',
					) );
			   ?>
			</nav>
			
			<div class="x-nav-wrap mobile collapse">
			   <?php
					wp_nav_menu( array(
					  'menu' => 'Blog Menu',
					  'container'      => false,
					  'menu_class'     => 'x-nav sf-menu',
					) );
			   ?>
			</div>

          
      <?php else: ?>
          <?php x_get_view( 'global', '_nav', 'primary' ); ?>
      <?php endif; ?>
      <?php //end where I added code ?>
          
    </div>
  </div> <!-- end .x-navbar-inner -->
</div> <!-- end .x-navbar -->
<?php else : ?>
<?php x_get_view( 'global', '_brand' ); ?> <?php if(is_home()): ?> <?php wp_nav_menu( array( 'menu' => 'Blog Menu', 'container' => false, 'menu_class' => 'x-nav sf-menu', ) ); ?> <?php else: ?> <?php x_get_view( 'global', '_nav', 'primary' ); ?> <?php endif; ?>
<?php endif; ?>

I cannot for the life of me figure out why it won’t display correctly.

Hello There,

Thanks for writing in! Your modification is quite complicated which resulted to more issues. I would recommend that you remove your _navbar.php file and make use of this alternative and easy solution. Assuming that you already get get rid of the file, all you have to do is to add the following code in your child theme’s functions.php file

// Output Primary Navigation
// =============================================================================

if ( ! function_exists( 'x_output_primary_navigation' ) ) :
  function x_output_primary_navigation() {

    if ( x_is_one_page_navigation() ) {

      wp_nav_menu( array(
        'menu'           => x_get_one_page_navigation_menu(),
        'theme_location' => 'primary',
        'container'      => false,
        'menu_class'     => 'x-nav x-nav-scrollspy',
        'link_before'    => '<span>',
        'link_after'     => '</span>'
      ) );

    } elseif ( has_nav_menu( 'primary' ) ) {

    	if ( is_home || is_single() ) {

    		// display blog menu in blog index and single post items
    		wp_nav_menu( array(
			  'menu' => 'Blog Menu',
			  'container'      => false,
			  'menu_class'     => 'x-nav sf-menu',
			) );

    	} else {

    		// display the primary menu in all other areas
    		wp_nav_menu( array(
			  'theme_location' => 'primary',
			  'container'      => false,
			  'menu_class'     => 'x-nav',
			  'link_before'    => '<span>',
			  'link_after'     => '</span>'
			) );
    	}

    } else {

      echo '<ul class="x-nav"><li><a href="' . home_url( '/' ) . 'wp-admin/nav-menus.php">Assign a Menu</a></li></ul>';

    }

  }
endif;

We would loved to know if this has work for you. Thank you.

Thank you so much! I worked on that for 2 months straight and couldn’t get it to work. You fixed it! You’re a genius. Thank you so much!!!

You’re most welcome! :slight_smile: