0

I'm a bit puzzled why the title callback of /user produces the title for /user/register and /user/password.

When I set the title callback of /user, I see this affects the title of /user/register and /user/password. However, setting a title callback for /user/register seems to make no difference; it appears to stick to the title callback of /user.

What is special about /user/register and /user/password which results in titles for these callbacks to have their titles produced by the title callback of /user?

function mytheme_menu_alter(&$items) {
  $items['user']['title callback'] = 'mytheme_user_title';
}

function mytheme_user_title($title) {
  return 'test';
}
  • Do you mean the title User account or the title of the tab e.g. Register for user/register? – Kartagis Feb 8 at 10:39
  • I mean the page title. The mytheme_user_title for user generates the page title for user/register and user/password. – sbrattla Feb 8 at 11:32
  • Does it have to be in theme? – Kartagis Feb 8 at 11:36
0

For the user/register title to be changed in a theme:

function mytheme_preprocess_page(&$variables) {
  // Only act when the first part of the url equals 'user', the second
  // part is 'register'
  $arg = arg();
  if ($arg[0] == 'user' && $arg[1] == 'register') {
    $variables['title'] = 'Test';
  }
}

For the user/register title to be changed in a module:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form') {
  drupal_set_title(t('Test'));
  }
}

Hope that helps.

  • Thanks, but setting $variables['title'] doesn't truly change the title - it only changes the rendered title. And changing the title via form_alter results in the page title being changed even if I, say, embed that form in another page... – sbrattla Feb 8 at 12:01
  • You lost me - what does "doesn't change the title but rendered title" mean? – Kartagis Feb 8 at 12:03
  • When you set $variables['title'], that is only a title for the page theme file. Other parts of the site will keep using the 'real' title (browser bar title, metatag module etc etc). – sbrattla Feb 8 at 12:18
  • You said user/register, I gave you such an example. – Kartagis Feb 8 at 12:19
  • @sbrattla is saying that, using the code shown for hook_preprocess_page(). other modules would still think the page title is the one set in his mytheme_user_title(), since the title is changed right before the page is rendered. – kiamlaluno Feb 8 at 16:16

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.