Unregister Nav Menu with fallback?

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:

Read More
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?

Related posts

Leave a Reply

1 comment

  1. You can filter 'wp_nav_menu_args', set an invalid theme_location and the magic function __return_false as fallback:

    add_filter( 'wp_nav_menu_args', 'override_parent_args' );
    
    function override_parent_args( $args )
    {
        if ( 'header-menu' === $args['theme_location'] )
        {
            $args['fallback_cb']    = '__return_false';
            $args['theme_location'] = 'ticky_tacky';
        }
    
        return $args;
    }