I am trying to build a importer which once import everything including pages will assign the some pages to the menus I have added during import. I have so far maanged to import pages, post , images and work out to add menus in specific location. But I can not add pages to the menus so the demo import remains incomplete.

$locations = get_theme_mod( 'nav_menu_locations' );
            $registred_menus = wp_get_nav_menus();
            if( $registred_menus ) {
                foreach( $registred_menus as $menu ) {
                    if( $menu->name == 'Menu demo 1' ) {
                        $locations['primary'] = $menu->term_id;
                        $menu->count = 8;
                    if( $menu->name == 'footer menu' ) {
                        $locations['footer'] = $menu->term_id;

            set_theme_mod( 'nav_menu_locations', $locations );

The above code works and I can see two menus in the menu section. How do I add pages in this menu? any hook or function or point me towards something so that I can walk on.

Your Answer

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

Browse other questions tagged or ask your own question.