Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drupal 8 Get node ID by path alias
<?php
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');
if(preg_match('/node\/(\d+)/', $path, $matches)) {
$node = \Drupal\node\Entity\Node::load($matches[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment