V
V
Vladimir2015-05-19 15:30:55
Drupal
Vladimir, 2015-05-19 15:30:55

How to add class to a tag (Drupal 7)?

There is a menu displayed by a block, you need to assign the tags (a) a bootstrap class (btn) what function can this be predefined? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
afi13, 2015-05-19
@afi13

Try the Menu attributes
module . With it, you can specify a class for any menu item.
Or you need to override theme_menu_link() in your theme.

V
Vladimir, 2015-05-19
@seoyuzer

Now there is a function on the site

function mythemes_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  
  if (isset($element['#original_link']['mlid'])) {
    $element['#attributes']['class'][] = 'mlid'.$element['#original_link']['mlid'];
  }

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

It adds a class for all li in the menu, maybe add something to this function so that the class is assigned to the tag as well ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question