How do I display a username on their profile pages? Using Drupal 8, I simply want a user's profile (or account) page to show its username, like so:

For username "bob":

Username: bob

Do I add a computed field? What's a line of code would I use?
Do I add a computed field?


No


  What's a line of code would I use?


In your theme's .theme file add:

/**
 * Implements hook_preprocess_HOOK().
 */
function THEMENAME_preprocess_page_title(&amp;$variables) { // your theme might already have this function/hook.
  $user = \Drupal::request()-&gt;attributes-&gt;get('user');
  if ($user instanceof \Drupal\user\UserInterface) {
    $variables['title'] = t('Username') . ': ' . $user-&gt;getAccountName();
  }
}


Note: Clear/flush the cache for changes to kick in.