Stop! Wait a moment!

Do you want to change your life? Join me on my 50-Day Life Transformation Challenge. Get involved! It won't cost you anything except a few bad habits.

How to Change the Title of a Drupal Form (Drupal 9 & 10)

Drupal user registration form

If you want to change the title of a form, whether it's the title of the registration form or a node add form, you have two options:

Here's an example of how to change the title of the registration form:

1. Use the hook_preprocess_page_title

/**
 * Implements hook_preprocess_HOOK().
 */
function MYTHEME_MYMODULE_preprocess_page_title(&$variables) {
  if (\Drupal::routeMatch()->getRouteName() == 'registration_link.register') {
    $variables['title'] = t('New Title');
  }
}

2. Utilize the hook_preprocess_html

/**
 * Implements hook_preprocess_HOOK().
 */
function MYTHEME_MYMODULE_preprocess_html(&$variables) {
  if (\Drupal::routeMatch()->getRouteName() == 'registration_link.register') {
    $variables['head_title']['title'] = t('New Title');
  }
}

These two approaches allow you to customize the title of a Drupal form of your choice. Replace 'New Title' with the desired title text you want to display.

Tags

Comments

Restricted HTML

  • Allowed HTML tags: <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Subscribe to my Newsletter

Join a growing community of friendly readers. From time to time I share my thoughts about rational thinking, productivity and life.