0

Theme Developer shows me that I need to use theme_links()

I can use this function, but I want to alter markup for main menu only.

I've tried funtion names: mytheme_links__menu_main_menu or mytheme_links__system_main_menu

but it seems that these function aren't invoked.

1

One way to achieve this to create a theme key in your template file like this:

function THEMENAME_theme(){
    $items = array();

    $items['custom_main_menu'] = array(
      'variables' => array('links' => array()),
  );

  return $items;
}

And then use the function below

function THEMENAME_custom_main_menu($menu){
  $menu['links'][367]['#below'][526]['#attributes']['id'] = "news_ma_international";
  // this will add id to link # 367
}

Now to print the main menu in your page.tpl.php use something like this

 <?php $main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu')); ?>
                <?php print theme('custom_main_menu', array(
                  'links' => $main_menu_tree,
                  'attributes' => array(
                    'id' => 'main-menu-links',
                    'class' => array('links', 'clearfix'),
                  ),
                  'heading' => array(
                    'text' => t('Main menu'),
                    'level' => 'h2',
                    'class' => array('element-invisible'),
                  ),
                )); ?>

I hope this will help!

2
  • I've found that preprocessing custom menu is much easier. For main menu? Major pain in the ass
    – Codium
    Oct 29 '15 at 18:14
  • @drupality: I am not sure I understand your message.
    – Shabir A.
    Oct 29 '15 at 18:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.