Drupal 10: Check To See If The Current Route Is The Front Page

The path.matcher service can be used to detect the front page of the site.

$isFront = \Drupal::service('path.matcher')->isFrontPage();
if ($isFront) {
  // Do something.
}

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
4 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.