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.
Was This Tutorial Helpful?