1

I have a parent theme that is using this code to create menus:

function cornerstone_menus() {

    register_nav_menus(
        array(
            'header-menu-left' => __( 'Header Menu (left)', 'cornerstone' ),
            'header-menu-right' => __( 'Header Menu (right)', 'cornerstone' ),
            'footer-menu' => __( 'Footer Menu', 'cornerstone' )
        )
    );

}
add_action( 'init', 'cornerstone_menus' );

In my child theme, I want my own menus, so I've created them, but these three parent theme menu items still show up in the Appearance > Menu section. I have a function in my child theme that removes the menus:

function remove_cornerstone_menus() {
    unregister_nav_menu( 'header-menu-left' );
    unregister_nav_menu( 'header-menu-right' );
    unregister_nav_menu( 'footer-menu' );
}

but I don't know what action to tie it to in order for it to work. I assumed that since the menu creation is being called in the "init" action, I could do this:

add_action('init', 'remove_cornerstone_menus');

But the menus still show up. I read elsewhere that I needed to hook into the after_setup_theme action, so I tried this:

add_action('after_setup_theme', 'remove_cornerstone_menus');

But that didn't work either. I'm at a loss as to how to remove the menus. I can manually remove them, but if the theme updates I'll have to do it again, and I'm trying to avoid that, which is why I'm using a child theme. Can anyone point me in the right direction?

1

Of course right after I post this, I find an answer...so hopefully someone else can benefit from this. For me, the answer was instead of unregistering nav menu items, I needed to just remove the action...so my function now looks like this:

function remove_cornerstone_menus() {
    remove_action('init', 'cornerstone_menus');
}

add_action('init', 'remove_cornerstone_menus');

Worked like a charm.

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.