Question
How to override page title in drupal8?
Solution
use $variables['title']
in function THEMENAME_preprocess_page_title(&$variables) { }
to set the page title.
Example
/**
* @param $variables
*/
function mytheme_preprocess_page_title(&$variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
switch ($node->getType()){
case "article":
$variables['title'] = t('News');
break;
case "page":
if ( $node->id() == "3"){
$variables['title'] = t('Page Title');
}
break;
}
}
}