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


Comments

40 responses to “Remove Navigation Menu From Specific Page”

  1. Hi Brad, I try to Remove Secondary Navigation Menu From my woo commerce page , but it doesn’t work.
    code as this,
    [code]
    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’ );
    }
    }
    [/code]

    1. Brad Dalton Avatar
      Brad Dalton

      What theme are you using?

          1. yes, I have read.
            I add
            [code]
            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’,
            ) );
            }
            }
            [/code]

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

          2. Brad Dalton Avatar
            Brad Dalton

            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

            [code]
            //* 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’ );
            [/code]

            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.

          3. sorry, i change the code as this
            [code]
            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’ );
            }
            }
            [/code]

            but…. it won’t work.

          4. Brad Dalton Avatar
            Brad Dalton

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

            [code]
            remove_action( ‘genesis_before_content_sidebar_wrap’, ‘genesis_do_nav’ );

            remove_action( ‘genesis_before_footer’, ‘genesis_do_subnav’ );
            [/code]

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

  2. blogambitions Avatar
    blogambitions

    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?

    1. Brad Dalton Avatar
      Brad Dalton

      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.

      1. blogambitions Avatar
        blogambitions

        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

        1. Brad Dalton Avatar
          Brad Dalton

          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:

          [code]
          remove_action(‘genesis_after_header’, ‘genesis_do_nav’ );
          [/code]

          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.

          1. blogambitions Avatar
            blogambitions

            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)?

          2. Brad Dalton Avatar
            Brad Dalton

            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.

          3. Brad Dalton Avatar
            Brad Dalton

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

            [code]
            && !is_page(’62’)
            [/code]

            So the entire line looks like this:
            [code]
            if ( is_front_page() || is_page() && !is_page(’62’)) {
            [/code]

            Or
            [code]
            if ( is_front_page() || is_singular(‘page’) && !is_page(’62’)) {
            [/code]

          4. Brad Dalton Avatar
            Brad Dalton

            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 Avatar

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

    is that intentional?

  4. Diego Avatar

    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

    1. Brad Dalton Avatar
      Brad Dalton

      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.

      1. diego Avatar

        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

        1. diego Avatar

          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!

          1. Brad Dalton Avatar
            Brad Dalton

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

        2. Brad Dalton Avatar
          Brad Dalton

          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.

  5. Yuri Yeleyko Avatar
    Yuri Yeleyko

    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:)
    [code]
    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’);
    }
    }
    [/code]

    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!

    1. Brad Dalton Avatar
      Brad Dalton

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

      1. Yuri Yeleyko Avatar
        Yuri Yeleyko

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

        1. Brad Dalton Avatar
          Brad Dalton

          No worries. Glad you worked it out Yuri.

  6. 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.

  7. 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.

    1. Brad Dalton Avatar
      Brad Dalton

      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.

      1. 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.

        1. Brad Dalton Avatar
          Brad Dalton

          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.

          1. 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.

          2. Brad Dalton Avatar
            Brad Dalton

            Couldn’t see any hook in that code.

            You could simply hide it using CSS code instead.

  8. Brad Dalton Avatar
    Brad Dalton

    Please paste the code in a Gist or use Pastebin.

    1. m3325xb Avatar

      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.

  9. Stacey Pruim Avatar
    Stacey Pruim

    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:
    [code]
    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’);
    }
    }
    [/code]
    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?

    1. Brad Dalton Avatar
      Brad Dalton

      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.

  10. 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?

    1. Brad Dalton Avatar
      Brad Dalton

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

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.