1

I need to change the default title tag for the maintenance page, which currently is "Site under maintenance | [sitename]".

I tried to set $variables['head_title'] in hook_preprocess_maintenance_page() but it doesn't work.

Also I think it can be set in hook_preprocess_html(), but I don't know how to check the served page is the maintenance page.

How can I achieve this?

1

TEMPLATE_preprocess_maintenance_page changes only variables for maintenance-page.html.twig. But <title> is outputted in html.html.twig, so you have to choose another preprocessor template_preprocess_html. So you can use this code(don't forget to clean cache after it):

function mytheme_preprocess_html(&$variables) {
  $maintenance_mode = \Drupal::state()->get('system.maintenance_mode');
  if (!empty($maintenance_mode)) {
    $variables['head_title'] = (string)t('My Custom Maintenance Title');
  }
}
0

To change this message, you can go Adm -> Config -> Maintenance page and write you own message.

If you really want do this in a preprocess function:

function TEMPLATE_preprocess_maintenance_page(&$variables) {
  $variables['head_title'] = "A custom var that YOU going to use in maintenance-page.html.twig";
  $variables['title'] = "Default var used to display title message 'Site under maintenance' ";
}

Or you can even override maintenance-page.html.twig file to put your own message, but its not the best option.

  • In Config -> Maintenance page I can change message only. But I need to change title tag. And I already tried using preprocess function for it, but it doesn't affect anything. And it's the problem. – iamdroid Feb 26 '16 at 12:26
  • @paulanders Edit your question to provide more information about your context because there is no title tag or 'head_title' by default in maintenance-page.html.twig. Are you using a custom theme, module or whatever? Are you using preprocess functions in a module or a theme? My answer works ok in a clean install of Drupal 8. – Vagner Feb 26 '16 at 12:50

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.