Accessing hreflang in a preprocessor or twig layer
function MODULE_page_attachments_alter(array &amp;$attachments) {
 foreach ($attachments['#attached']['html_head'] as $can_key =&gt; $can_value) {
       foreach ($can_value as $low_value) {
          if (isset($low_value['#attributes']['rel']) &amp;&amp; $low_value['#attributes']['rel'] == 'alternate') {
             // Unset canonical tags if present there.
             $attachments['#attached']['html_head'][$can_key]['#attributes']['hreflang'] = 'your value';
           }
        }
     }
}