You can do this by creating custom module and creating yourmodule.services.yml
services:
yourmodule.breadcrumb:
class: Drupal\yourmodule\FwsBreadcrumbBuilder
tags:
- { name: breadcrumb_builder, priority: 100 }
and creating custom class which should extend BreadcrumbBuilderInterface like this
class FwsBreadcrumbBuilder implements BreadcrumbBuilderInterface {
public function applies(RouteMatchInterface $route_match) {
$route = $route_match->getCurrentRouteMatch();
// Add conditionals that return TRUE when the current route should have it's
// breadcrumb handled here.
return FALSE;
}
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$breadcrumb->addCacheContexts(['route']);
// Add logic here that builds up the breadcrumbs based on desired behaviour.
$links[] = Link::createFromRoute(t('Home One'), '<front>');
$breadcrumb->setLinks($links);
return $breadcrumb;
}
}
I have also got the above code from http://drupal.stackexchange.com
You can also add new and alter previous breadcrumbs in hook_preprocess_HOOK function like this
function yourmodule_or_yourtheme_preprocess_breadcrumb(&$variables) {
// Your Logic Here
}