Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

A similar question was asked about buddypress here , but I tried applying it to a twentythirteen, and I am getting this error.

Cannot use object of type stdClass as array in /hsphere/local/home/c349026/expressbraiding.com/blog/wp-admin/menu.php on line 25

How I can I properly apply the code bellow to a twenty thirteen child theme?

 //give your menu a name
 $name = 'theme default menu';
 //create the menu
 $menu_id = wp_create_nav_menu($name);
 //then get the menu object by its name
 $menu = get_term_by( 'name', $name, 'nav_menu' );
 //then add the actuall link/ menu item and you do this for each item you want to add
wp_update_nav_menu_item($menu->term_id, 0, array(
'menu-item-title' =>  __('Home'),
'menu-item-classes' => 'home',
'menu-item-url' => home_url( '/' ), 
'menu-item-status' => 'publish'));
 // you add as many items ass you need with wp_update_nav_menu_item()

//then you set the wanted theme  location
$locations = get_theme_mod('nav_menu_locations');
$locations['LOCATION_NAME'] = $menu->term_id;
set_theme_mod( 'nav_menu_locations', $locations );

Thanks to @bainternet

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.