In my project I would like to add the following attributes to my "Login" main menu item:

data-toggle="modal" data-target="#login-modal" (Am using the Bootstrap theme)

I checked out the menu attribute module but it does not allow for these attributes.

Please is there a way?

3 Answers 3


You can use this HOOK_menu_link_alter and add new attribute from there.


function MYMODULE_menu_link_alter(&$item) {
  if ($item['link_path'] == 'user/login') {
    $item['options']['attributes']['data-toggle'] = 'modal';
    $item['options']['attributes']['data-target'] = '#login-modal';

Note : Make sure you clear cache and are checking this for anonymous user.


You can change the menu attribute module

If you are in drupal 7 Just install and enable menu attribute module module then go to module directory and edit menu_attributes.module to add following lines to menu_attributes_menu_attribute_info() function

Before return $info; line

//Added by ErangaJ 
$info['data-toggle'] = array(
'label' => t('Data toggle'),
$info['data-target'] = array(
'label' => t('Data target'),
  • You should never, ever change a contrib module code. Use alters to do this instead.
    – macjules
    Commented Jul 22, 2016 at 13:21

You can use drupal module Bootstrap login modal

Adds a login and register link in the nav bar. Opens them in Bootstrap Modals.

This module is intended for use with the Bootstrap theme.

By default the login and register links are added to the navigation region, but they can be moved on the block admin page.

  • Hi makbuk and welcome. Please try to prevent link-only answers and include a relevant part of the answer in your post, optionally providing a link for further reference. It will give the OP a better idea of what to expect and your post will contain it's value in case the link would go down. Commented Jun 10, 2016 at 8:41

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.