0

Is it possible to not have a menu on post pages. I think it would be something like "if page show menu, if post don't show menu" but I'm not sure how to put that into PHP.

Thanks

1
  • can you tell me which menu you want to hide wp_nav_menu(); or your custom menu?
    – Anjum
    Aug 23 '13 at 11:53
1
if (is_single()) {
 // DONT SHOW MENUS
}

you may pass a post id for any specific post for eg -

if (is_single('4')) {
     // DONT SHOW MENUS
    }

will execute on post with id = 4 . hope it helps

5
  • prince what is if_single() it's is_single() or use if (is_single()) { // some code }
    – Anjum
    Aug 23 '13 at 11:49
  • oops i made mistake there thankyou for pointing out.. Aug 23 '13 at 11:51
  • Thanks, I understand it but I'm not sure how to write the don't show part? I have <nav><?php categories() ?></nav>
    – Nsokyi
    Aug 23 '13 at 11:59
  • if (!is_single()) { // show menus here.ie you wp_nav_menu() funtion...simple ? } Aug 23 '13 at 12:00
  • Ah, yes I think I have it working now I went with: <?php if( (is_single()) || (is_page('about')) || (is_page('contact') )) { ?> <style type=""> .cat_nav_wrap { display: none; } </style> <?php } ?>
    – Nsokyi
    Aug 23 '13 at 13:13
1

While you can use CSS to hide elements, I don't think it's ideal, especially for something like a menu. In effect, that element and its queries will still run and load (and therefore affect your page's speed), only to be hidden by the CSS.

I would recommend, instead, either editing your theme's header.php or creating a child theme with a new header.php file that conditionally loads the menu on pages that aren't single.php. In the TwentyThirteen theme, fr'ex, you would use the following in your header.php file:

  <?php if (is_singular()) :
        // DO NOTHING
  else : ?>
           <div id="navbar" class="navbar">
              <nav id="site-navigation" class="navigation main-navigation" role="navigation">
                 <h3 class="menu-toggle"><?php _e( 'Menu', 'twentythirteen' ); ?></h3>
                 <a class="screen-reader-text skip-link" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentythirteen' ); ?>"><?php _e( 'Skip to content', 'twentythirteen' ); ?></a>
                 <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
                 <?php get_search_form(); ?>
              </nav><!-- #site-navigation -->
           </div><!-- #navbar -->
  <?php endif ?>
1
  • Wow, thanks for doing that. Your right that seems like a much better approach. Thank you.
    – Nsokyi
    Aug 24 '13 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.