Modify metatag description programmatically Drupal 8 I modified the meta-tag title for a view in hook_preprocess_html() using the following code.

if (isset($variables['head_title'])) {
    $variables['head_title'] = $variables['page']['#title'] . " | My web";
}


Is it possible to modify the description in the same hook?
That depends on your theme and its use of $variables in combination with the description meta tag.

A code snippet for Drupal 8 that does what you want for the Bartik Theme would be the following:

function bartik_page_attachments_alter(array &amp;$page) {
  $description = array(
    '#type' =&gt; 'html_tag',
    '#tag' =&gt; 'meta',
    '#attributes' =&gt; array(
      'name' =&gt; 'description',
      'content' =&gt; 'your description content',
    ),
  );
  $page['#attached']['html_head'][] = [$description, 'description'];
}


This was inspired by this post => https://drupal.stackexchange.com/a/134145/57183

Maybe this does solve your problem!