I am trying to create a child theme so theme updates are much easier. I want to remove the parent theme menus and add my own. I know I can modify the header.php file (where these menus exist) and edit the wp_nav_menus directly, but I’m trying to avoid using as many theme files as possible, so I’m trying to accomplish this in my functions.php file.
Using unregister_nav_menu I am able to remove the menu from the parent theme location as such:
function RR_remove_parent_theme_menus() {
unregister_nav_menu( 'top-menu' );
unregister_nav_menu( 'header-menu' );
}
add_action( 'after_setup_theme', 'RR_remove_parent_theme_menus', 20 );
This works great for “top-menu” but “header-menu” is coded in the parent theme with a custom fallback. Is there any way to override a custom (or a default) menu fallback using unregister_nav_menu or something else?
You can filter
'wp_nav_menu_args'
, set an invalidtheme_location
and the magic function__return_false
as fallback: