<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\Routing\RouteCollection;

/**
 * Implements hook_preprocess_page().
 */
function hide_login_title_preprocess_page(array &$variables) {
  $route_name = \Drupal::routeMatch()->getRouteName();

  // Hide page title only on login, registration, and password reset pages.
  $routes_to_hide = [
    'user.login',
    'user.register',
    'user.pass',
  ];

  if (in_array($route_name, $routes_to_hide, TRUE)) {
    // Remove title and wrapper variables.
    $variables['title'] = '';
    $variables['title_prefix'] = [];
    $variables['title_suffix'] = [];
  }
}

/**
 * Implements hook_route_alter().
 */
function hide_login_title_route_alter(RouteCollection $collection) {
  // Get the route definition for the login page.
  if ($route = $collection->get('user.login')) {
    // Change its title to empty.
    $route->setDefault('_title', '');
  }
}