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.


  • can you tell me which menu you want to hide wp_nav_menu(); or your custom menu?
    – Anjum
    Commented Aug 23, 2013 at 11:53

2 Answers 2

if (is_single()) {

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

if (is_single('4')) {

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

  • prince what is if_single() it's is_single() or use if (is_single()) { // some code }
    – Anjum
    Commented Aug 23, 2013 at 11:49
  • oops i made mistake there thankyou for pointing out.. Commented Aug 23, 2013 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
    Commented Aug 23, 2013 at 11:59
  • if (!is_single()) { // show menus here.ie you wp_nav_menu() funtion...simple ? } Commented Aug 23, 2013 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
    Commented Aug 23, 2013 at 13:13

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 ?>
  • Wow, thanks for doing that. Your right that seems like a much better approach. Thank you.
    – Nsokyi
    Commented Aug 24, 2013 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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