I'm creating my menu using view along with Bootstrap to create a mega menu style navigation.

I'm having a problem with the nav showing expanded at times when you come to the site and or refresh. not all the time but more than I'd like.

I am using: _menu_link like such:

function MYTHEME_menu_link(array $vars) {
  if ( $vars['element']['#theme'] == 'menu_link__user_menu' ) {
    $vars['element']['#attributes']['class'][] = '';
  elseif ( $vars['element']['#theme'] == 'menu_link__main_menu' ) {
    $vars['element']['#attributes']['class'][] = 'dropdown mm-menu-fw';
    $vars['element']['#localized_options']['attributes']['class'][] = 'url-link';
  return theme_menu_link($vars);

This gives me the following HTML markup.

<ul class="dropdown mm-menu-fw">
    <a href="#" class="url-link">MY LINK</a>
    <ul class="NEED-TO-ADD-CLASS"></ul>

You might get into the sub menu element with the ['#below'] object. not tested.


    * Implements theme_menu_link__[MENU NAME].
   function YOURTHEME_menu_link__main_menu(&$variables) {       

        $element = $variables['element'];
        $sub_menu = '';         

        $element['#attributes']['class'][] = 'dropdown mm-menu-fw';        
        $element['#localized_options']['attributes']['class'][] = 'url-link';

        if ($element['#below']) 
         $sub_menu = $element['#below']['#attributes']['class'][]= 'NEED-TO-ADD-CLASS';

       $output = l($element['#title'], $element['#href'], $element['#localized_options']);

       return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";

  • Trying this out now and will let you know what comes of this. Thank you – TikaL13 Feb 9 '15 at 17:12

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.