1

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?

0

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;
}
2
  • How would I filter it to be /completely/ gone? I don't want any remnants of the container or the contents in there. Apr 30 '13 at 19:36
  • 1
    @RodeoRamsey Maybe an invalid theme_location with __return_false as fallback_cb?
    – fuxia
    Apr 30 '13 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.