• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

Remove Navigation Menu From Specific Page

There’s different ways to remove or hide your primary and secondary nav menus in WordPress.

The best way is to create a custom function and add it to your child themes functions.php file.

You can use this code with any theme by changing the hooks depending on which theme you’re using.

You can also choose from a list of conditional tags depending on which pages/posts you want to remove the nav menu from.

On top of this you can change the code for either the primary or secondary navigation menu.

These code snippets relate to the Genesis theme framework.

Remove Primary Navigation Menu From Front Page

add_action('get_header', 'child_remove_genesis_do_nav');
function child_remove_genesis_do_nav() {
if (is_front_page()) {
remove_action('genesis_before_header', 'genesis_do_nav');
}
}

When Primary Nav Menu After Header Use This Code:

add_action('get_header', 'child_remove_genesis_do_nav');
function child_remove_genesis_do_nav() {
if (is_front_page()) {
remove_action('genesis_after_header', 'genesis_do_nav');
}
}

Remove Primary Navigation Menu From Home, Archive and Static Pages

Remove Secondary Navigation Menu From Home Page

This code will remove the secondary navigation menu from the homepage only.

add_action('get_header', 'child_remove_genesis_do_subnav');
function child_remove_genesis_do_subnav() {
if (is_home()) {
remove_action('genesis_after_header', 'genesis_do_subnav');
}
}

Remove Primary Navigation Menu From Home Page

This code will remove the primary navigation menu from the homepage only.

add_action('get_header', 'child_remove_genesis_do_nav');
function child_remove_genesis_do_nav() {
if (is_home()) {
remove_action('genesis_after_header', 'genesis_do_nav');
}
}

Remove Primary Navigation Menu From Category Pages

This code will remove the primary navigation menu from all category archive pages.

add_action('get_header', 'child_remove_genesis_do_nav');
function child_remove_genesis_do_nav() {
if (is_category()) {
remove_action('genesis_after_header', 'genesis_do_nav');
}
}

Remove Secondary Navigation Menu From Specific Page

This code will remove the secondary navigation menu from a specific page using the page i.d 007.

Remove Primary Navigation Menu From Specific posts

This code will remove the primary navigation menu from a specific posts using the post i.d 007.

Remove Primary Navigation Menu From 404 Page Template

This code will remove the primary navigation menu from the 404 page template

add_action('get_header', 'child_remove_genesis_do_nav');
function child_remove_genesis_do_nav() {
if (is_page_template('404') ) {
remove_action('genesis_after_header', 'genesis_do_nav');
}
}

You can also add the code directly to any type of page template:

remove_action('genesis_after_header', 'genesis_do_nav');

That’s just a few code snippets you can add to your child themes functions.php file to remove different nav menus based on specific conditions.

Other Nav Menu Solutions

  • Change Primary Nav Menu For Specific Page(s) In Any Theme

Reader Interactions

Comments

  1. WWHaT says

    February 12, 2017 at 8:18 am

    Hi Brad, I try to Remove Secondary Navigation Menu From my woo commerce page , but it doesn’t work.
    code as this,

    add_action('get_header', 'child_remove_genesis_do_subnav');
    function child_remove_genesis_do_subnav() {
    if (is_woocommerce() or is_checkout() or is_account_page() or is_cart() or is_product() or is_shop()) {
    remove_action( 'genesis_after_header', 'genesis_do_subnav' );
        }
    }
    Log in to Reply
    • Brad Dalton says

      February 12, 2017 at 8:25 am

      What theme are you using?

      Log in to Reply
      • WWHaT says

        February 12, 2017 at 8:34 am

        prettychic

        Log in to Reply
        • Brad Dalton says

          February 12, 2017 at 9:00 am

          Please read this

          Log in to Reply
          • WWHaT says

            February 12, 2017 at 9:16 am

            yes, I have read.
            I add

            remove_action( 'genesis_after_header', 'genesis_do_nav' );
            remove_action( 'genesis_after_header', 'genesis_do_subnav' );
            
            at the end 
            
            add_theme_support ( 'genesis-menus' , array ( 
                'primary' => 'Primary Navigation Menu' , 
                'secondary' => 'Second Navigation Menu' ,
                'woocommerce-menu' => 'WooCommerce Menu' 
            ) );
            
            //* Hook menu after header conditionally
            add_action( 'genesis_after_header', 'woocommerce_shop_page_menu', 12 );
            function woocommerce_shop_page_menu() {
            
            if ( ! class_exists( 'WooCommerce' ) )
                return;
            
            if ( is_woocommerce() or is_checkout() or is_account_page() or is_cart() or is_product() or is_shop() ) {
            	genesis_nav_menu( array(
            		'theme_location' => 'woocommerce-menu',
            		'container'      => false,
            		'depth'          => 1,
            		'fallback_cb'    => false,
            		'menu_class'     => 'genesis-nav-menu wrap',
            	) );
                }
            }

            And I have ask to you from that questions, but I still can’t resolve my problem, I am very sorry.

          • Brad Dalton says

            February 12, 2017 at 9:24 am

            You can use that code to remove the nav menus because they are NOT hooked using the genesis_after_header hook.

            If you look at in the functions file around line 128, you’ll find the code which changes the hook

            //* Reposition Navigation Menus
            remove_action( 'genesis_after_header', 'genesis_do_nav' );
            add_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_nav' );
            
            remove_action( 'genesis_after_header', 'genesis_do_subnav' );
            add_action( 'genesis_before_footer', 'genesis_do_subnav' );

            That tells you that you need to remove the primary nav from the genesis_before_content_sidebar_wrap hook location

            and the secondary nav from the genesis_before_footer hook location.

            The code you are trying to use, uses the genesis_after_header hook location, therefore it won’t work.

          • WWHaT says

            February 12, 2017 at 9:39 am

            sorry, i change the code as this

            add_action('get_header', 'child_remove_genesis_do_subnav');
            function child_remove_genesis_do_subnav() {
            if (is_woocommerce() or is_checkout() or is_account_page() or is_cart() or is_product() or is_shop()) {
            remove_action( 'genesis_before_footer', 'genesis_do_subnav' );
            remove_action( ' genesis_before_content_sidebar_wrap', 'genesis_do_nav' );
                }
            }

            but…. it won’t work.

          • Brad Dalton says

            February 12, 2017 at 10:03 am

            I just tested this code in functions so i know it works:

            remove_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_nav' );
            
            remove_action( 'genesis_before_footer', 'genesis_do_subnav' );

            So you just need to hook it in. Try another hook instead of get_header.

  2. blogambitions says

    March 2, 2015 at 9:04 pm

    Hey Brad. I did the method: Remove Primary Navigation Menu From Home, Archive and Static Pages. Except, I deleted the || is_archive() because I want it to show up on the archive pages. Basically, I just don’t want it showing up on the home or static pages.

    It worked great, except it the nav menu doesn’t show up on the “blog” page. I tried using both the genesis blog template as the blog page, and setting the blog page through the WP reading settings. Home being the static page and blog being the posts page.

    Neither displays the blog page. I’m assuming because it is a page? Any suggests for displaying it on the blog feed page?

    Log in to Reply
    • Brad Dalton says

      March 2, 2015 at 11:49 pm

      Hi Kristy

      The blog page is a problem and maybe removed from Genesis at some stage. Even the Genesis Devs say not to use it.

      I use the default reading settings and just add a link to a page using the blog page template.

      If you don’t use the default reading settings, you might need to use is_front_page() rather than is_home()

      To remove from static pages, try !is_singular(‘page’) or is_singular(‘page’)) depending on how you have coded it.

      is_home() relates to your posts page according to your reading settings but using a conditional for the blog page template isn’t stable, works in some cases and not in others.

      Please let me know if this has helped or whether i need to take a deeper look.

      Log in to Reply
      • blogambitions says

        March 5, 2015 at 9:03 pm

        Okay, so I changed my Reading settings and selected: A static page. Set the front page: home (just a blank page) and blog page as blog (again, just a blank page).

        When I did that though, the blog page adapted the home page and the home page grid section no longer displayed the blog posts.

        I am using Minimum Pro.

        The code to remove the primary nav. is actually working 95% like I want it to, I just also want the nav menu to show up on the “blog” page. Whether that page is set up the genesis way or the standard way.

        add_action('get_header', 'child_remove_genesis_do_nav');
        /**
        *@author Brad Dalton
        *
        *@Link http://wpsites.net/web-design/remove-nav-menu-specific-page/
        */
        function child_remove_genesis_do_nav() {
        if ( is_home() || is_page()) {
        remove_action( 'genesis_after_header', 'genesis_do_nav', 15 );
        }
        }

        This is a test site, and not really ready for viewing, but you can check it out here. A lot of the links don’t work, since it’s just a test site.

        test.blogambitions.com

        test.blogambitions.com/test

        Thanks, Kristie

        Log in to Reply
        • Brad Dalton says

          March 6, 2015 at 1:48 am

          Change is_home() conditional tag to is_front_page and use the default reading settings.

          You could also add the code directly to the front-page.php file:

          remove_action('genesis_after_header', 'genesis_do_nav' );

          And then remove is_home() from your custom function.

          The problem is the blog page template uses the page body class so its treated like a page.

          Leave this with me and i’ll work it out.

          Log in to Reply
          • blogambitions says

            March 6, 2015 at 2:22 am

            okay. Back to working like it originally was. Which is perfect, just need it to show up on the blog page. Is there a way to exclude a page from an exclusion (condition)? Haha.

            Am I having to use the default reading settings with a blog template page because of the theme I am using (minimum pro)?

          • Brad Dalton says

            March 6, 2015 at 2:24 am

            Here’s the solution http://wpsites.net/wordpress-themes/remove-nav-menu-from-front-page-single-pages-exclude-blog-page/

            Let me get back to you on the 2 other questions shortly.

          • Brad Dalton says

            March 6, 2015 at 2:31 am

            Yes, add this and change the I.D for the page which you can grab from the source code.

            && !is_page('62')

            So the entire line looks like this:

            if ( is_front_page() || is_page() && !is_page('62')) {

            Or

            if ( is_front_page() || is_singular('page') && !is_page('62')) {
          • Brad Dalton says

            March 6, 2015 at 2:37 am

            You could use the reading settings to select a static page for posts but you wouldn’t get use of the Genesis Blog Page Template settings.

            All child themes include the blog page template as its included in Genesis.

  3. raunek says

    May 10, 2014 at 6:36 am

    most of your pages are not accessible and coming with “forbidden” error…

    is that intentional?

    Log in to Reply
  4. Diego says

    May 2, 2014 at 12:48 am

    Hi Brad,

    I need urgent help. I wanted to remove Menu from one landing page. I copy and paste the following in my php file:

    But now I get a: Parse error: syntax error, unexpected ‘:’ in /home/judiosyj/public_html/wp-content/themes/metro-pro/functions.php on line 162 and I cannot even log in to my admin to change it!

    I would greatly appreciate your help!
    Thank you very much

    Log in to Reply
    • Brad Dalton says

      May 2, 2014 at 1:22 am

      Diego

      There is NO : is any of the code on this page so it has nothing to do with my code.

      Please paste PHP code into a Github Gist and embed or link to it from here otherwise it will break the code.

      Log in to Reply
      • diego says

        May 2, 2014 at 1:33 am

        Hi Brad,

        Thank you for your quick reply.
        I don’t know how to use Guthub. I just pasted the code that appears after the following title: Remove Primary Navigation Menu From Home, Archive and Static Pages

        After doing that I got the following error: Parse error: syntax error, unexpected ‘:’ in /home/judiosyj/public_html/wp-content/themes/metro-pro/functions.php on line 162

        So I hit the back button to the editor and remove the entire code. But now the problem persists and I cannot even access my admin.

        Do you have any idea what might have happened? What could I do?

        Thank you!
        Diego

        Log in to Reply
        • diego says

          May 2, 2014 at 1:38 am

          Ok, this is what my functions.php looks right now

          It is interesting that it says the error is in line 162 and the Github shows up to 154 total!

          Log in to Reply
          • Brad Dalton says

            May 2, 2014 at 2:14 am

            Remove the closing Curly bracket from the end of the file.

        • Brad Dalton says

          May 2, 2014 at 2:12 am

          Looks like you copied the title as well which includes the :

          You need to go into the file using FTP or File Manager in cPanel and remove the code.

          Log in to Reply
  5. Yuri Yeleyko says

    January 20, 2014 at 6:50 pm

    Brad, thanks so much! I’ve been looking couple days for it.
    There is one small typo for Removing Primary navigation from posts, you stated subnav instead of nav:)

    add_action('get_header', 'wpsites_remove_genesis_do_nav');
    
    function wpsites_remove_genesis_do_nav() {
    if (is_single('15279') ) {
    remove_action('genesis_after_header', 'genesis_do_nav');
     }
    }

    Also, may I ask you if it is possible to remove custom menus (like in widget) on certain posts. What should we use, an ID and how to create the code for functions.php?
    Thanks again!

    Log in to Reply
    • Brad Dalton says

      January 21, 2014 at 1:40 am

      You can use the Widget Logic plugin or add a conditional tag after the function which creates the widget to exclude pages.

      Log in to Reply
      • Yuri Yeleyko says

        January 21, 2014 at 9:09 am

        Thank you, the Widget Logic worked for me just fine!

        Log in to Reply
        • Brad Dalton says

          January 21, 2014 at 2:26 pm

          No worries. Glad you worked it out Yuri.

          Log in to Reply
  6. John says

    October 9, 2013 at 11:12 am

    Hello,
    yes i set the css to hide the menu in the page body, but it was a nice thing to do it by the hard way to learn more about wordpress technicals.
    Someday i hope.
    Thanks for you help.

    Log in to Reply
  7. John says

    October 7, 2013 at 9:55 am

    Hello, i prefer using my pseudonym on the network but in real life people call me John.
    The reason i came to you is the forum of the skeleton forum is closed until the next update of the theme come out. I’m sorry if it’s not appropriate to ask you for help but i’m searching for a solution and i found your post about removing navigation from specific page and that is exactly what i need.
    Best regards.

    Log in to Reply
    • Brad Dalton says

      October 7, 2013 at 10:54 am

      Hi John

      I would need to load up the them locally and test out the code to see if it works otherwise i would be guessing.

      I’d say your theme uses different hooks to what Genesis uses so i would need to see all the code.

      Sorry i can’t help you in this case however i think the forums for your theme are the best place to ask a theme specific question.

      Log in to Reply
      • John says

        October 7, 2013 at 12:48 pm

        I understand it could be to much work.
        I’m learning what are Hooks and functions. I think i need to implement the hook in function.php to not showing the menu on my template page.
        Don’t worry, thanks you so much for your excellent work.
        Have a good day.

        Log in to Reply
        • Brad Dalton says

          October 7, 2013 at 12:53 pm

          If i knew what hooks your theme uses, i could provide you the code however i do not have access to your themes support forum or documentation.

          All you would need to do is replace the genesis hook with your theme specific hook in the code included in this post and it will work.

          Log in to Reply
          • John says

            October 7, 2013 at 2:54 pm

            I’m pretty sure the hook i need to custom is this but i can’t make it work with the code of your post

            Here the original hook i need to custom :
            https://gist.github.com/anonymous/6869183

            Here what i try to do but it’s doesn’t work :
            https://gist.github.com/anonymous/6869309

            Thank you for your help.

          • Brad Dalton says

            October 8, 2013 at 12:00 am

            Couldn’t see any hook in that code.

            You could simply hide it using CSS code instead.

  8. Brad Dalton says

    October 7, 2013 at 2:03 am

    Please paste the code in a Gist or use Pastebin.

    Log in to Reply
    • m3325xb says

      October 7, 2013 at 8:49 am

      Ok sorry again*2 (now i know) + sorry for my English. 🙂

      So here the part of code in the function.php that create the function or hook (st_navbar).

      & here the part of code in the header.php that call the navmenu (st_navbar).

      & here the part of code in the page-template.php that call the header part

      Thank you.

      Log in to Reply
  9. Stacey Pruim says

    October 2, 2013 at 4:18 pm

    Hey there,
    Tried to mod for a site I have where I need the primary navigation to be hidden for some member pages but I’m using the secondary menu for those.

    the page id’s are:
    693, 695, 697, 699, 701, 808, 810, 813, 815, 817, 819, 821, 823, 834, and 955

    Tried adding your code as this:

    add_action('get_header', 'wpsites_remove_genesis_do_nav');
    
    function wpsites_remove_genesis_do_nav() {
    if (is_page( array( 693, 695, 697, 699, 701, 808, 810, 813, 815, 817, 819, 821, 823, 834, 955
    ) ) ){
    remove_action('genesis_after_header', 'genesis_do_nav');
    }
    }

    It gives me an error:
    Parse error: syntax error, unexpected $end in /home3/meghantt/public_html/wp-content/themes/lifestyle/functions.php on line 112

    I can’t see what I’ve done wrong…
    Can you help?

    Log in to Reply
    • Brad Dalton says

      October 2, 2013 at 9:36 pm

      Hi Stacey

      Please clarify ” need the primary navigation to be hidden for some member pages but I’m using the secondary menu for those’.

      Code for the primary nav will not work for the secondary nav unless you modify it to do so.

      This code works to remove the secondary nav menu on the pages corresponding to the page i.d’s for the menu in the after header theme location.

      Log in to Reply
  10. Kristi says

    April 26, 2013 at 7:27 pm

    If we wanted to remove the primary navigation for the home page as well as 2 other pages would we do the
    if (is_page( array( 001, 0022 ) )
    sort of like removing it from a specific page but using a array?

    Log in to Reply
    • Brad Dalton says

      April 27, 2013 at 3:00 am

      That’s right Kristi. You can add as many page i.d’s to the array as you like.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags