4

Secondary menu - this is the system secondary menu title. I need to replace it with current username, the same as the User menu block has it.

I do not want to use the User menu block because of some reasons. I would like to use the deafault system menu:

<?php if ($secondary_menu): ?>
  <div id="secondary-menu" class="navigation">
    <?php print theme('links__system_secondary_menu', array(
      'links' => $secondary_menu,
      'attributes' => array(
        'id' => 'secondary-menu-links',
        'class' => array('links', 'inline', 'clearfix'),
      ),
      'heading' => array(
        'text' => t('Secondary menu'),
        'level' => 'h2',
        'class' => array('element-invisible'),
      ),
    )); ?>
  </div> <!-- /#secondary-menu -->
<?php endif; ?>

Should I use token [current-user:name]? If so, then where (file name) and how?

Note: I can not do it directly at /admin/structure/menu/manage/user-menu/edit because Menu name field is inactive.

7
  • So, are you just want instead of My account it will show the current login user-name in the default secondary menu? What drupal version are you using?
    – CodeNext
    Commented Oct 4, 2016 at 5:44
  • No! I need to replace the system title - Secondary menu - with username. I can not do it directly at /admin/structure/menu/manage/user-menu/edit because Menu name field is inactive. Drupal 7. Thank you
    – ttt
    Commented Oct 4, 2016 at 5:59
  • but Secondary menu word does not appear in the User interface anywhere as far as I know. Secondary menu show, only My account and Logout While User Menu Block will show menu-title User menu then two list My account and Logout. These five thing appears to user. out of these which one you wan tot change.
    – CodeNext
    Commented Oct 4, 2016 at 6:15
  • This is hided by CSS. Look at HTML and you can see it - Secondary menu. I need to replace it with username.
    – ttt
    Commented Oct 4, 2016 at 6:34
  • /** * Override or insert variables into the block template. */ function bartik_preprocess_block(&$variables) { // In the header region visually hide block titles. if ($variables['block']->region == 'header') { $variables['title_attributes_array']['class'][] = 'element-invisible'; } }
    – ttt
    Commented Oct 4, 2016 at 6:37

1 Answer 1

4

I think you can simply do this by making change in page.tpl.php file.

Just replace,

'text' => t('Secondary menu'),

with,

'text' => t($user->name),

save and clear cache.

Image-1: Before changing code (I have deleted line 'class' => array('element-invisible'), so text can be visible)

enter image description here

Image-2: After change,

enter image description here

Final code,

<?php if ($secondary_menu): ?>
      <div id="secondary-menu" class="navigation">
        <?php print theme('links__system_secondary_menu', array(
          'links' => $secondary_menu,
          'attributes' => array(
            'id' => 'secondary-menu-links',
            'class' => array('links', 'inline', 'clearfix'),
          ),
          'heading' => array(
            //'text' => t('Secondary menu'),
            'text' => t($user->name),
            'level' => 'h2',
            //'class' => array('element-invisible'),
          ),
        )); ?>
      </div> <!-- /#secondary-menu -->
    <?php endif; ?>
3
  • CodeNext, thank you! This is exactly what I need :)
    – ttt
    Commented Oct 4, 2016 at 10:35
  • Yes your answer is very helpful but I do not know how to close it and how to up-vote. Pls advice :)
    – ttt
    Commented Oct 4, 2016 at 10:42
  • I tried to do it but not sure if it was done because I am not registered here on this site. Later I will register (sign up) and will do all the neccessary things.
    – ttt
    Commented Oct 4, 2016 at 10:57

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.