Jump to content

Recommended Posts

Hi,

 

need some help to hide / remove  the wp_nav_menu from my index page.

 

I'm using the the Tesseract theme, nav_menu is located in the header

 

I got a advice to commenting out the code, but I just don't seem to get it right.

 

<?php $anyMenu = get_terms( 'nav_menu' ) ? true : false;
          $menuSelect = get_theme_mod('tesseract_tho_header_menu_select');
                    
               if ( $anyMenu && ( ( $menuSelect ) && ( $menuSelect !== 'none' ) ) ) :     
                  wp_nav_menu( array( 'menu' => $menuSelect, 'container_class' => 'header-menu' ) );                       
        

               elseif ( $anyMenu && ( !$menuSelect || ( $menuSelect == 'none' ) ) ) :
                         $menu = get_terms( 'nav_menu' );
                         $menu_id = $menu[0]->term_id;

                        wp_nav_menu( array( 'menu_id' => $menu_id ) );
        

               elseif ( !$anyMenu ) :
                      wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );                        
        endif; ?>

 

 

Thank you in advance for any kind of help! / Jo'

Link to comment
https://forums.phpfreaks.com/topic/298491-how-to-remove-wp_nav_menu-from-a-page/
Share on other sites

I usually make plugins to add or remove certain things

if(is_front_page() || is_home()){
    if (function_exists('wp_nav_menu')) {
        remove_action('wp_head', 'wp_nav_menu');
    }
}

In your case wrap the code you have with a check for not home or front page

<?php
if(!is_front_page() && !is_home()){
 $anyMenu = get_terms( 'nav_menu' ) ? true : false;
          $menuSelect = get_theme_mod('tesseract_tho_header_menu_select');
                    
               if ( $anyMenu && ( ( $menuSelect ) && ( $menuSelect !== 'none' ) ) ) :     
                  wp_nav_menu( array( 'menu' => $menuSelect, 'container_class' => 'header-menu' ) );                       
        
               elseif ( $anyMenu && ( !$menuSelect || ( $menuSelect == 'none' ) ) ) :
                         $menu = get_terms( 'nav_menu' );
                         $menu_id = $menu[0]->term_id;
                        wp_nav_menu( array( 'menu_id' => $menu_id ) );
        
               elseif ( !$anyMenu ) :
                      wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );                        
        endif;
}
?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.