Skip to content

Instantly share code, notes, and snippets.

@mikedotexe
Created June 20, 2017 18:57
Show Gist options
  • Save mikedotexe/c2a5304f47618dbb7dd9c27b8c727457 to your computer and use it in GitHub Desktop.
Save mikedotexe/c2a5304f47618dbb7dd9c27b8c727457 to your computer and use it in GitHub Desktop.
Get homepage path of Drupal 8 site from configuration
<?php
use Drupal\Core\Config\Config;
// ...
$config = \Drupal::config('system.site');
$front_uri = $config->get('page.front');
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($front_uri);
@fmuellerprevion
Copy link

That snippet did what I googled for over one hour. Thank you!

@renzy
Copy link

renzy commented Mar 26, 2019

tyty. exactly what i was looking for. getPathByAlias doesnt seem to return node id for the frontpage, all the other search results were saying to use that but failed to note it wouldnt work if you were dealing with the front, at least for drupal 8.6.4

@Ambient-Impact
Copy link

If you're doing this in anything but a procedural function, you should make sure to use dependency injection as using the Drupal global static object is meant only for legacy code and is considered bad practice elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment