Programmatically add items to the menu - not hook_menu We're redesigning our site and getting rid of the sidebar. The main reason for the sidebar to exist was to hold Organic Menus (og_menu), which we have hundreds of groups, each with 2 or 3 menus. I want to move OG menus to the main menu.

What I would like to do is when a user visits a particular OG


load the menus for that OG (trivial)
programmatically make the menu's name the top level links linked to # (Trivial - we use bootstrap)
add the menu's links below those top level links (this is where it gets tricky)
and append them to the main menu as the last to links (no clue)


So the top level would look like this only when the user hit the group 

Home Communities Forum Group-Menu-1 Group-Menu-2

Home, communities and forum are always there the group menus are appended when they're in that group. I don't need code I just need direction on which parts of the API will facilitate this.
I solved this by just appending my links to the menu tree with hook_preprocess_menu_tree

&lt;?php

function my_module_preprocess_menu_tree(&amp;$vars) {

  if($vars['theme_hook_original'] != 'menu_tree__primary') {
    return;
  }

  $node = menu_get_object();

  //Check to see if this is a group node or group content and return the group_node
  $group_node = my_module_check_for_group_node($node);

  if($group_node) {

    global $user;

    $vars['tree'] = str_replace('last leaf', 'leaf', $vars['tree']);

    $result = db_query('SELECT menu_name FROM og_menu WHERE gid = :nid ORDER By weight', array(':nid' =&gt; $group_node-&gt;nid));

    $menus = $result-&gt;fetchAll();

    foreach($menus as $menu) {
      $tree = menu_tree($menu-&gt;menu_name);

      if(!empty($tree)) {
        // render the organic group menu as HTML
        $tree = drupal_render($tree);

        $tree = str_replace('menu nav', 'dropdown-menu', $tree);

        $menu_array = menu_load($menu-&gt;menu_name);

        //format &lt;li&gt; and top-level &lt;a&gt; for bootstrap
        $li = '&lt;li class="expanded dropdown"&gt;&lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;'.$menu_array['title'].'&lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;'.$tree.'&lt;/li&gt;';

        $vars['tree'] .= $li;
      }
    }

    $vars['tree'] .= $li; 
 }
 ?&gt;