I am trying to make a custom taxonomy breadcrumbs based the code from this question: Drupal 8 How to do a custom taxonomy breadcrumb?

This line adds a new breadcrumb for the home page:

$breadcrumb->addLink(Link::createFromRoute(t('Home'), 'front'));

PS: I removed parenthesis from front to display line here.

I want to add another breadcrumb with the text of the name of a taxonomy term and the URL of the same term:

$breadcrumb->addLink(Link::createFromRoute(t($term->getName()), $url));

I cannot figure out how to replace "front" with the route name of the $term object.

  • try using like $breadcrumb->addLink(\Drupal\Core\Link::fromTextAndUrl(t($term->getName()), $url)));
    – Ajay Reddy
    Commented Oct 17, 2017 at 14:12
  • fromTextAndUrl Function takes url object as an input, how can i get the url object of a certain term ? Commented Oct 17, 2017 at 14:30
  • Use this \Drupal\Core\Url::fromUserInput("YOUR LINK GOES HERE")
    – Ajay Reddy
    Commented Oct 17, 2017 at 14:32
  • see also drupal.stackexchange.com/questions/233530/…
    – HongPong
    Commented Apr 24, 2018 at 18:25

1 Answer 1


Since taxonomy terms are entities, you can simply do this:

$link = $term->toLink();

As a side-note, the route name for taxonomy terms is "entity.taxonomy_term.canonical".


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.