Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The class for the "My Account" menu item in the User menu is not showing up as "active" or "active-trail" when I go to that page.
Steps taken:
1. I enabled My Account menu in the User menu.
2. Go to the page, but the menu item is not active.
3. The html is not showing the list item as "active-trail" or "active". Same goes for the anchor tag.
Comments
Comment #1
Nick_vhWe (together with randy) reproduced this issue and I tried finding documentation about how to set a certain item as active
http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_set_ac...
Also, in further investigation we found that the active link logic happens in function menu_navigation_links
http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_naviga...
The output of the debug session we held gave the following results :
The logic is expecting the path to be
user/1 (user/%user)
But instead the link that we click on to go to my account is
user
There is some automatic magic going on in redirect /user to /user/%user and therefore I guess the active link is not set
Comment #2
jeckman CreditAttribution: jeckman commentedReproduced with fresh install of Drupal 7.8, no additional modules, Bartik theme.
Same symptoms as described. Tried with clean urls enabled and disabled.
The classes assigned are:
Comment #3
pandersb CreditAttribution: pandersb commentedHad to add a module with hook_menu_alter() and then enable the menu link. The active trail finally came through.
Comment #4
Ghostthinker CreditAttribution: Ghostthinker commented#3 not working for me, did you change your custom module weight?
Comment #5
netboss CreditAttribution: netboss commentedAdding this function to my template.php worked for me:
I know this is kind of "hacky", but it solved my problem.
Hopefully this help!
Comment #6
Ghostthinker CreditAttribution: Ghostthinker commented@netboss thank you. Works for me. Here is a slighly modified version that also respects user/*
This works for me. Maybe there should be a menu_set_active_trail somewhere if you have a user submenu (not tabs).
Comment #7
Abbass CreditAttribution: Abbass commentednone of the above works for me, however setting in the css header-menu ul.menu li.active-trail works for the other tabs of my Main menu
Comment #8
inventlogic CreditAttribution: inventlogic commented#6 combined with #5 placed in template.php works for me.
Anyway of adding the .active-trail as well?
Comment #9
ñull CreditAttribution: ñull commentedConfirming the same bug with Sasson theme. Subscribing and bumping.
#5 nor #6 are working for me.
Comment #10
chanderbhushan CreditAttribution: chanderbhushan commentedYou can put this css :--
#header-menu .content > ul > li.active-trail > a,
#header-menu .content > ul > li > a.active {
color: #1a272e;
background-color: #f8f8f8;
font-weight: 700;
}
OR
You can add unique class through php code :
Comment #11
sunI may be mistaken, but this sounds like a duplicate of #1564388: "My account" link is never in the active trail
Comment #12
warmth CreditAttribution: warmth commentedOn #5 you can add
<?php global $user; ?>
and replace
<?php drupal_match_path(current_path(),"user/*") ?>
with
<?php drupal_match_path(current_path(),"user/".$user->uid) ?>
to only get that behavior for the current user on his profile.
Comment #13
WorldFallz CreditAttribution: WorldFallz commentedJust an update that combines 5,6, &12 (you don't need the
global $user
):This shows "My Account" on the user's profile page, but leaves it alone for other user profiles.
Comment #14
hkirsman CreditAttribution: hkirsman commented#13 worked for me!
Comment #15
danabel CreditAttribution: danabel commented#13 worked great for me until I added a sub page to the menu item and it didn't show up as a child when the menu item was active.
As a solution I have installed the menu_token module and set the URL to
user/[current-user:uid]
. This way everything works as expected including sub-menus. Also if the current-user token doesn't exist the menu item isn't displayed which is perfect for my needs.Comment #16
jweirather CreditAttribution: jweirather commented#13 worked great for me to highlight the menu item for /user for the user path with the active menu classes for active or active-trail, such that when a user visits the /user page, the corresponding menu item for the user account is highlighted as active.
In template.php, wrapped in a hook like in earlier posts. Adding my final code and some keywords ^^^:
It seems odd to me that this doesn't happen OOTB.
Comment #17
jweirather CreditAttribution: jweirather commentedDid not mean to update version. 7.x dev is all that's showing available now.