How to hide the menu on a particular page? (8 posts)

  1. mnml55
    Posted 2 years ago #

    I'm running on the default Twenty Eleven them, and I'd like to hide the navigation menu on a particular page, but still display my logo etc in the header.

    I expect I'd have to create a custom template to do so, but I'm unsure as to which file is the default template to modify - could anyone shed some light as to where I should start?


  2. Santosh
    Posted 2 years ago #

    you can create your own page template and use on page css like this

    .menuclass{ display:none;} (menuclass should be your class name)

  3. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #

    for a css quick-fix, you could use the body_class() output of .page-id-123 (where 123 is the page ID) together with the css id of the menu, to hide the menu:


    .page-id-123 #access { display: none; }

  4. mnml55
    Posted 2 years ago #

    @Santosh and @alchymyth - Thanks, but I'm still not sure where to start - you say 'create your own page template', but what do I base it on?

    If at all possible, I'd rather go down the custom template route so that I can simply select it in the future whenever I want a menu-less page. How would I go about this?

  5. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #


    possibly start with a copy of page.php of your theme ...

    as the menu is called in teh header.php, you will also need to edit that;

    once you know the file name of your page template (where you do not want to show the menu) you can use a conditional statement with is_page_template() http://codex.wordpress.org/Conditional_Tags#Is_a_Page_Template to wrap the menu code;

    example (there is one new line before the <nav..> section, and one after):

    <?php if( !is_page_template('no-menu-page-template.php') : ?>
    			<nav id="access" role="navigation">
    				<h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?></h3>
    				<?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
    				<div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to primary content', 'twentyeleven' ); ?></a></div>
    				<div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?></a></div>
    				<?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assigned to the primary location is the one used. If one isn't assigned, the menu with the lowest ID is used. */ ?>
    				<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
    			</nav><!-- #access -->
    <?php endif; ?>

    this assumed that the new page template's file name is 'no-menu-page-template.php'

  6. mnml55
    Posted 2 years ago #

    @alchymyth That looks exactly like what I need! For some reason I'm getting a syntax errors on opening an closing though - do you have any idea why? I can't see any reason why I would get one?


    Thanks for your help, I really do appreciate it!

  7. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #

    I missed a bracket ;=(

    <?php if( !is_page_template('no-menu-page-template.php') ) : ?>
  8. mnml55
    Posted 2 years ago #


    Thank you so much, you are awesome! (:

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.