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?

5 Answers 5


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');

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, 2016 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, 2016 at 12:50

On Drupal 9 with a subtheme from Bootstrap 5, I used this function to change the head title and the page title.

 * Implements theme_preprocess_html().
function TEMPLATE_preprocess_html(&$variables) {
  $maintenance_mode = \Drupal::state()->get('system.maintenance_mode');
  if (!empty($maintenance_mode)) {
    $title = t('My Custom Maintenance Title');
    $variables['head_title']['title'] = $variables['page']['#title'] = $title;

If you don't want to write php code,you can try this↓

Since the maintenance setting page(/admin/config/development/maintenance) supports JS, it may be possible to solve this indirectly by adding the following code

<script type="text/javascript">
  document.title="your custom title"
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jun 19, 2023 at 12:21

If you have access to the backend, you can modify the string directly for a temporary change. Change /var/www/html/ to the location of your install and other strings to fit your needs.

  1. Login with SSH. ssh [email protected]
  2. Edit the file /var/www/html/includes/common.inc with your favorite text editor and replace Site under maintenance with your new message. You could also use sed. sed -i 's/Site under maintenance/Your new title here/' /var/www/html/includes/common.inc
  3. Clear the cache. cd /var/www/html/ && drush cc all

This will be overwritten after an update to Drupal Core.


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.