Drupal 8 : Get content owner or author name of a node using node id.

To load the author name or owner from a  node entity object we can use getOwner(). The below example show how to load a node object using node id and to get the Author name from it.

Sample code:

$entity_obj = entity_load('node', 7);
$author_name = $entity_obj->getOwner()->getDisplayName();
print_r(‘The author name is :. $author_name);


The author name is : Anishnirmal