Very new to Drupal and a bit confused.

In order to render a menu in my theme I've been using this:

print theme('links', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links')))); 

That works a treat and gives me an extra class on the first and last list items, which I need for styling. It doesn't, however, show any of the nested sub menus. So I found this that again, worked like a charm Show all nested menu links in Drupal 7 and shows all the top-level links in the main menu and the nested ones too. This doesn't give me the extra classes on the first and last list items which I need. Is there any way to use the code from the answer above and give the extra classes on the list items?

Thanks muchly

1 Answer 1


Check out the Menu Attributes module. Here is a quote about it (from the module's project page):

This simple module allows you to specify some additional attributes for menu items such as id, name, class, style, and rel.

You should use this module when

  • You want to "nofollow" certain menu items to sculpt the flow of PageRank through your site
  • You want to give a menu item an ID so you can easily select it using jQuery
  • You want to add additional classes or styles to a menu item
  • Boom! Nice one fella. Just what I needed. If I had some rep, I'd up-vote you......
    – toby_lh
    Mar 5, 2013 at 13:12
  • I did it for you.
    – SpaceBeers
    Mar 5, 2013 at 13:34
  • Cheers SpaceBeers. Top name btw.
    – danbohea
    Mar 5, 2013 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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