I have a module that contains multiple forms, each form in its own file. I need to modify the page title such that it is different from the browser title for several of these pages. The name of the module is member_login. This is what I have so far:

function member_login_preprocess_page(&$variables) {
  if (\Drupal::routeMatch()->getRouteName() == 'member_login.login') {
    $variables['content']['#title'] = t("The new HTML title.");

I add this function to the .module file. Do I need to call it, or does Drupal call it automatically for it to come into effect? Currently, I do not see it into effect.

  • Where exactly in what file are you placing that hook? It belongs into a *.module or *.theme file. Then you need an if-request to check for some URL or whatever pattern to apply your logic.
    – leymannx
    Jun 14, 2019 at 20:32
  • @leymannx I updated the original post with the updated code that I'm using. It is now placed in the *.module file, however still no success.
    – PHPDev
    Jun 14, 2019 at 20:38
  • Have you also tried this one: drupal.stackexchange.com/a/232783/15055
    – leymannx
    Jun 14, 2019 at 21:05


Browse other questions tagged or ask your own question.