4

I would like the change the default title (and probably also the meta title) of the User registration page, currently "Create new account".

I tried the Static and Dynamic page title method described here, as well as a couple of other suggestions, but none of them worked...

Anyone? I added a print screen of the route (registration_link.register), the URL is user/register.

default page title

2 Answers 2

7

You can add the following two hooks to your theme's *.theme file or your module's *.module file. The first to alter the title that's displayed in the page title block. The second to alter the meta title.

/**
 * Implements hook_preprocess_HOOK().
 */
function MYTHEME/MYMODULE_preprocess_page_title(&$variables) {

  if (\Drupal::routeMatch()->getRouteName() == 'user.register') {

    $variables['title'] = t('New Title');
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function MYTHEME/MYMODULE_preprocess_html(&$variables) {

  if (\Drupal::routeMatch()->getRouteName() == 'user.register') {

    $variables['head_title']['title'] = t('New Title');
  }
}
1
  • 1
    using 'registration_link.register' as route, the above code worked like a charm. Thanks!
    – user89568
    Sep 26, 2018 at 7:51
0

In Drupal 9 this will be

/**
 * Implements hook_preprocess_HOOK().
 */
function MYTHEME/MYMODULE_preprocess_page_title(&$variables) {

  if (\Drupal::routeMatch()->getRouteName() == 'registration_link.register') {

    $variables['title'] = t('New Title');
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function MYTHEME/MYMODULE_preprocess_html(&$variables) {

  if (\Drupal::routeMatch()->getRouteName() == 'registration_link.register') {

    $variables['head_title']['title'] = t('New Title');
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.