Check if on front page

Public

Create or add this to the preprocess function, then check against $is_front_page in the template

Get raw version
php
  1. function yourtheme_preprocess_foo(&$variables) {
  2. // Create a variable to return TRUE, if on the front page
  3. $is_front_page = \Drupal::service('path.matcher')->isFrontPage();
  4. // Make that available to any templates preprocessed by this function.
  5. $variables['is_front_page'] = $is_front_page;
  6. }