Make Theme automatically choose default nav menu

You can use has_nav_menu() to check to see if the location has one assigned to it. If it does, use wp_get_nav_menu_items() to duplicate the menu, then assign it to the location you register in your theme.

Here’s what I have in mind. It’s off the top of my head and will need more code and testing, but hopefully it’s a good start for you:

function wpse112672_menus() {
    if( has_nav_menu( 'old_theme_menu_location' ) {
        $old_menu = wp_get_nav_menu_items( 'old_menu_id' );
        register_nav_menu( 'new_theme_menu_location' );
        $new_menu = wp_nav_menu( $args );

        return $new_menu;
    } else {
        return wp_page_menu();
    }
}

Leave a Comment