Create a menu item whenever a taxonomy term is created

function your-module-name_taxonomy_term_insert($term) {
$menu_item = array(
'link_title' => $term->name,
'menu_name' => 'your-menu-machine-name', // It uses '-', not '_'
'customized' => 1, // Must be 1 in order to not dispaly the link in any language
'link_path' => 'taxonomy/term/' . $term->tid, // menu_link_save() does not like aliases. Then 'nid' is used
'language' => 'en', // language is required in order to make the item translatable
'plid' => $plid, // id of the sub-menu if you want to add this in sub-menu
'weight' => '-50',
);
$mlid = menu_link_save($menu_item); // You don't need to receive it in a variable
$ml = menu_link_load($mlid); // I'm loading $mlid just to display the result and verify it
}
}

Advertisements