0

Trying to modify Parent Menus function on child theme, the original function is:

function original_theme_menus() {
    $menus = array(
        'top'       => __( 'Top Menu', 'theme-domain' ),
        'primary'   => __( 'Primary Menu', 'theme-domain' ),
        'secondary' => __( 'Secondary Menu', 'theme-domain' ),    
    );
    return apply_filters( 'original_theme_menus', $menus );
}

I'm doing:

function remove_original_theme_menus() {
    remove_action('original_theme_menus');
}
add_action('init', 'remove_original_theme_menus');

    function original_theme_menus() {
        $menus = array(
            'top'       => __( 'Top Menu', 'theme-domain' ),
            'primary'   => __( 'Primary Menu', 'theme-domain' ),
            'secondary' => __( 'Secondary Menu', 'theme-domain' ),
            'footer'    => __( 'Footer Menu', 'theme-domain' )

        );
        return apply_filters( 'original_theme_menus', $menus );
    }

How should I unregister the original function?

I get a Fatal Error because the original function is still there and cannot redeclare it.

I tried creating a new function name but the problem is the original one; If I just remove the original parent function everything works as expected.

I've read this and this to solve on my own but can not figure out what is the proper way to unregister~override the original menu function, and call it from child theme functions.

I presume it is also related with the "init" part because I should be doing this on the apply filters instead.

2
  • I tried changing init with after_setup_theme, an also different priorities, with no luck.
    – Nacionarte
    Mar 8, 2016 at 15:11
  • Please just wait two days until you mark the answer as solution. The same goes for answering your own question (which you can do).
    – kaiser
    Mar 8, 2016 at 16:01

1 Answer 1

0

You just need to fire the original one, not to remove.

add_filter( 'original_theme_menus', 'your_theme_menus', 1, 1 );
function your_theme_menus( $menus )
{
    $new_menu = array(
        'footer' => __( 'Footer Menu', 'theme-domain' )
    );
    $menus = $menus + $new_menu;

    return $menus;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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