How to programmatically add custom markup to every displayed user name Drupal 8.x

I am currently using hook_preprocess_user().

I would like to alter the username to add some custom markup to every username.

MYMODULE.module:

function MYMODULE_preprocess_user(&amp;$variables) {
  $variables['elements']['#user']-&gt;name-&gt;value = t('Name @newMarkup', ['@newMarkup' =&gt; ' Hello']);
}


This returns Name Hello Hello. Concatenation adds 'Hello' twice so this approach is not working.

I've also worked with user_format_name_alter(&amp;$name, $account), however, this does not seem to fit my use case.

How can I alter the username text? Not looking for a "currentUser" solution, but every user so names are changed everywhere. Reference, Views, etc.
Seems hook_user_format_name_alter() is your best bet. But same as in the other answer markup doesn't seem to be allowed everywhere. Normally the user name is only allowed to be a string.

The following won't work for Views for example. It will print just a string. 

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Implements hook_user_format_name_alter().
 */
function MYMODULE_user_format_name_alter(&amp;$name, $account) {

  $name = new TranslatableMarkup('@name &lt;span class="foo-bar"&gt;Foo Bar&lt;/span&gt;', ['@name' =&gt; $name]);
}

/**
 * Implements hook_preprocess_HOOK().
 */
function MYMODULE_preprocess_page_title(&amp;$variables) {

  if (\Drupal::routeMatch()-&gt;getRouteName() == 'entity.user.canonical') {

    $name = $variables['title']['#markup']-&gt;__toString();
    $variables['title'] = new TranslatableMarkup('@name &lt;span class="foo-bar"&gt;Foo Bar&lt;/span&gt;', ['@name' =&gt; $name]);
  }
}


So, what I'd recommend now is, you maybe take the *_preprocess_page_title hook – as this is working just fine on user pages – and for all other places (references, Views etc.) you maybe create a new custom formatter or pseudo field to do the job.