1

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

3

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
    using 'registration_link.register' as route, the above code worked like a charm. Thanks! – Dendreten Sep 26 '18 at 7:51

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.