I've been looking at using menu attributes module for Drupal 7 to add an extra field to the menu navigation system. However this adds a new attribute to the attribute array and thus prints it out in the anchor link.


  function themename_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below'])
    $sub_menu = drupal_render($element['#below']);

  $element['#localized_options']['html'] = TRUE;

  $subtitle = $element['#localized_options']['attributes']['subtitle']; //get sub text

  $linktext = $element['#title']. '<span>'. $subtitle .'</span>';
  $output = l($linktext, $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";

But it comes out like this

<a subtitle="subtitleexampletext" href="/node/13">About us<span>subtitleexampletext</span></a>

is there anyway to hide the attribute in the link and just spit it out where ever I want it in the html? Or is there a better way of doing this? I've looked at power menu module as well, but thats not quite what I'm after either.


1 Answer 1


You can use hook_form_alter to alter the menu link edit form. This way you can add a extra field to the form, in your case:

$form['subtitle'] = array(
 '#title'=> t('Subtitle'),

Then add an extra submit hanlder to the form:

$form['#submit'][] = '_my_submit_handler';

In your submit handler you can access your custom value by using $form_state['values']['subtitle'].

You will have to store this value in an extra sql table or a variable_set,together with the menu-item ID.

Once you have done that, in your theme function you can access your subtitle by menu id. Or you can use MYTHEME_preprocess_menu_link to add extra info to $variables, which you then can access in your theme function.

Hopes this helpes you out.

  • 1
    Hi @Robin - thanks for your answer, I went with just using the menu_link function and used unset to remove the variable from the attributes array. Not ideal but at least gets the outcome I want.
    – Jared
    Oct 31, 2014 at 2:21

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.