Drupal 8 | Add page title to the breadcrumb

I have noticed many default features introduced in Drupal 8 which is very essential. Drupal 8 has breadcrumb features by default it has default behaviour also. We can customize using below function. Add below function in your 'yourthemename.theme' file.

We can add current page title in breadcrumb using below hook. Make sure replace 'THEMENAME' function name with your theme name.

Example if your theme name is 'Classic' theme. Function theme should be 'Classic_preprocess_breadcrumb'.

function THEMENAME_preprocess_breadcrumb(&$variables){
   if(($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']){
	   $variables['breadcrumb'][] = array(
	     'text' => $node->getTitle(),
	     'url' => $node->URL()
	   );
	}
}
shanidkv's picture