1. Home
  2. Knowledge Base
  3. Hide WordPress menu and header on individual pages

Hide WordPress menu and header on individual pages

There are sometimes situations where you want to hide the WordPress menu and usually only want to hide the menu on a single page. Here you also have to differentiate whether you only want to hide the menu, i.e. the menu items, or also the complete WordPress header. That’s why I’m showing you here how it could possibly work.

The procedure depends very much on the WordPress theme used, so not all of the following solutions may work.

Hide the WordPress menu on individual pages

Option 1: Hide menu via “global” CSS

Although this variant is a bit of a “quick and dirty” option, it is the simplest and most promising variant. You can hide your WordPress menu with the following CSS code:
.page-id-XXX header nav {display: none;}
/* Ersetze XXX durch die page id deiner speziellen Seite */

Add this CSS code to your page. You can do this, for example, in the Customizer under “additional CSS”, the theme options (if your theme has theme options) or in your style.css file. If you enter the code in style.css, you should use a child theme and its style.css file.

Important: You have to replace the “XXX” in the CSS code with the page id of the page on which you want to hide the menu.

If the code does not work, try this one:
.page-id-XXX header .nav {display: none;}
/* Ersetze XXX durch die page id deiner speziellen Seite */

How to find out the page-id

There are two ways to find out the page-id.
Option 1:

  1. Go to the page on which you want to hide the menu.
  2. Right-click on the background or a free space on the page and click on “Examine element” or “Element information”.
  3. A window with the HTML code should now open. Search there for “

Option 2:

  1. Go to the WordPress edit mode of the page on which you want to hide the menu.
  2. You will now find the URL in the address bar at the top of your browser. The page-id also appears after “post=XXX”.

Option 2: Hide menu via page-specific CSS

This option is not quite as “dirty” as the 1st option. Some themes or page builders offer the option of entering and displaying CSS code for a specific page only. Visual Composer / WPBakery Page Builder and Elementor, for example, can do this.

Since the CSS code is then only executed on this one page anyway, it has the advantage that you don’t have to work with the page ids, as in option 1. So insert the following CSS code there:
header nav {display: none;}
If the code does not work, try this one:
header .nav {display: none;}

Option 3: Hide menu via PHP code

This option is by far the most difficult and also depends heavily on the theme you are using. However, this would be the “cleanest” method, because your menu is not only hidden, but does not even end up in the HTML source code.

With this method, the command wp_nav_menu(...), which fetches and displays your WordPress menu in the theme, is packed into a conditional statement (if statement). Then the menu is only displayed if the page id does not correspond to your specific page. The PHP code for this is something like:
<?php
if (!is_page(XXX)) {
wp_nav_menu(...);
}
?>

The XXX must be replaced by the page id.

The PHP code or the if statement around the wp_nav_menu command must be placed where your theme calls the wp_nav_menu command. Depending on the theme, this may be in a different place or a different PHP file. You may find the location in the header.php file. However, if you make changes to the theme files, you should use a child theme, otherwise your changes will be overwritten with the next theme update.

Hide the complete WordPress header on individual pages

You can not only hide the menu, but of course also hide the entire WordPress header on individual pages. The header here refers to the entire bar in which the menu is located, including the part where the logo, etc. is displayed.

To hide the header on individual pages, you basically have to use the same options 1 and 2 as for hiding the menu. Only the CSS code you have to insert looks a little different.

The CSS code for option 1 is:
.page-id-XXX header {display: none;}
/* Ersetze XXX durch die page id deiner speziellen Seite */

If the code does not work, try this one:
.page-id-XXX .header {display: none;}
/* Ersetze XXX durch die page id deiner speziellen Seite */

The CSS code for option 2 is:
header {display: none;}

If the code does not work, try this one:
.header {display: none;}

If none of the above CSS codes work, try adding “!important” after the “display:none”. So something like “…display:none !important;” (without quotation marks)

If you need more information on WordPress menus, I’ve written an article on how to create and edit a WordPress menu.

Dieser Beitrag ist auch verfügbar auf: Deutsch (German)

Was this article helpful?

Submit a Comment

Your email address will not be published. Required fields are marked *

Skip to content