Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

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;
    }
  }
}
Tags :

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon