There are a couple of solutions to change the page title
/**
* Implements THEME_preprocess_page_title()
*/
function THEMENAME_preprocess_page_title(&$variables) {
$current_url = \Drupal\Core\Url::fromRoute('<current>');
$url = $current_url->getInternalPath();
if($url == 'home') {
$variables['title'] = 'Welcome to Development Portal | ThirstySix';
}
}
/**
* Implements THEME_preprocess_page().
*/
function THEMENAME_preprocess_page(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node) {
$variables['title'] = $node->getTitle();
}
}
/**
* Implements hook_ENTITY_TYPE_view_alter().
*/
function MODULENAME_user_view_alter(array &$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) {
if ($entity->getEntityTypeId() == 'user') {
$build['#title'] = $entity->get('field_display_name')->getString();
}
}
- 3476 views
Add new comment