I'm using the Bootstrap theme and I've successfuly created a bootstrap subtheme that I named bootstrapdreve

I've already overidded successfully two templates, but now I'm facing a problem I'm stuck for hours on.

I wanted to overide the bootstrap_menu_link theming function located in bootstrap/theme/menu/. So I copied it into my


and renamed it

function bootstrapdreve_menu_link(array $variables)

Before bringing my adaptations I set a dsm('test'); on first line:

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

  if ($element['#below']) {
    // Prevent dropdown functions from being added to management menu so it
    // does not affect the navbar module.
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
      $sub_menu = drupal_render($element['#below']);
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
      // Add our own wrapper.
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
      // Generate as standard dropdown.
      $element['#title'] .= ' <span class="caret"></span>';
      $element['#attributes']['class'][] = 'dropdown';
      $element['#localized_options']['html'] = TRUE;

      // Set dropdown trigger element to # to prevent inadvertant page loading
      // when a submenu link is clicked.
      $element['#localized_options']['attributes']['data-target'] = '#';
      $element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
      $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
  // On primary navigation menu, class 'active' is not set on active menu item.
  // @see https://drupal.org/node/1896674
  if (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
    $element['#attributes']['class'][] = 'active';
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";

... and nothing's displayed

I've followed the idea given by this subtheme preprocess functions inheritance post by creating this structure:


and by setting also a dsm('test'); at first line of code...

Still no message... and thus as I interpret it no execution of this function...

I don't understand why. Could you please help me find why this theming function overiding doesn't work ?

Rem.: There's no problem with the dsm(), I've tried to put one at top of bootstrapdreve/template.php and it works fine...

Rem. 2: I've offcourse cleared the cache at every modification I made

  • If you put dsm() in the parent theme, can you verify it fires?
    – fmitchell
    Commented Feb 27, 2015 at 19:26
  • I've putted the dsm('test'); in the bootstrap/theme/menu/menu-link.func.php and there it fires well...
    – PolloFox
    Commented Feb 28, 2015 at 12:29
  • What version (revision) are you using of bootstrap theme, also you may check the changes in theme directory structure in issues #2170829, #2217037.
    – m.khamash
    Commented Mar 2, 2015 at 0:42
  • I'm using the 7.x-3.0 version. I've tried with an upgrade to the 7.x-3.1-beta2 version and it didn't change anything
    – PolloFox
    Commented Mar 2, 2015 at 21:13
  • can you confirm theme registry? $registry = theme_get_registry(); dsm($registry['menu_link']);
    – Abi أب
    Commented Mar 5, 2015 at 4:09

3 Answers 3


I maintain a Bootstrap subtheme that I use for most of my projects and I override theme_menu_link() in my subtheme using the same method with no problem:

 * Overrides bootstrap_menu_link().
 * Resets theme_menu_link() to the default that ships with Drupal. Bootstrap
 * attempts to make every menu with children into a dropdown menu. Remove this
 * function if you want drop down links.
function bootstrap_ignitor_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  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";

You must have a problem somewhere else.

  • You're right, the problem seems to be in my implementation of subtheme. I've gitted and activated your subtheme, set a dsm at the top of your bootstrap_ignitor_menu_link function and it displays well... Thanks for this trail.
    – PolloFox
    Commented Mar 2, 2015 at 21:15
  • @Adam Balsam, I made a mistake with the bounty, I wanted to assign 50 for you, sorry for that.
    – regilero
    Commented Mar 6, 2015 at 21:55
  • @regilero Ha! Oh well - glad it could point you in the right direction at least. Commented Mar 9, 2015 at 2:15

try using

option 1: function THEMENAME_menu_link(&$variables) {}

option 2:

* theme_menu_link()
function THEMENAME_menu_link(array $variables) {
//add class for li
   $variables['element']['#attributes']['class'][] = 'menu-' . $variables['element']['#original_link']['mlid'];
//add class for a
   $variables['element']['#localized_options']['attributes']['class'][] = 'menu-' . $variables['element']['#original_link']['mlid'];
  return theme_menu_link($variables);

option 3 :

function bootstrapdreve_preprocess_menu_link(&$variables) {
        $variables['element']['#attributes']['class'][] = 'menu-' . $variables['element']['#original_link']['mlid'];
        $menu_title_class = preg_replace("/[^a-zA-Z0-9]/", "-", strtolower(strip_tags($variables['element']['#title'])));
        // Another option $menu_title_class = preg_replace("/[^a-zA-Z0-9]/", "-", strtolower(strip_tags($variables['element']['#original_link']['link_title'])));
        $variables['element']['#attributes']['class'][] = 'menu-' . $menu_title_class;

        if ($variables['element']['#original_link']['menu_name'] == 'user-menu') {
            $variables['element']['#localized_options']['html']= true;
            $variables['element']['#title'] = '<span>'.$variables['element']['#title'].'</span>';
  • Neither of these options worked, but as Adam Balsam mentionned below, there must be something in the implementation of bootstrap subtheme I've done wrong, because with his subtheme, the dsm appears well...
    – PolloFox
    Commented Mar 2, 2015 at 21:18
  • So you have tried using (&$variables) instead of (array $variables) in your function call?
    – Darvanen
    Commented Mar 5, 2015 at 11:27

You need to add function bootstrapdreve_menu_link(array $variables) { in your template.php and not in a .func.php file. If you add it in a func.php file then you need to include this file in the template.php file somehow.

Just copy the code inside template.php and it should work.

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.