In Drupal 7 I used this to unset unneeded elements and total overwrite meta tags:
function MYTHEME_html_head_alter(&$head_elements) {
// Unset all.
$remove_array = array(
'system_meta_content_type',
'system_meta_generator',
'system_shortcut_icon',
'metatag_canonical',
);
foreach ($remove_array as $key) {
if ($head_elements[$key]) {
unset($head_elements[$key]);
}
}
// Optimize the mobile viewport.
$head_elements['mobile_viewport'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#weight' => -10,
'#attributes' => array(
'name' => 'viewport',
'content' => 'initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width',
),
);
// ...
// Many other my META tags
// ...
}
But in Drupal 8 this doesn't work anymore. New elements such as $head_elements['mobile_viewport']
don't get added.
And old meta tags, such as
<meta name="Generator" content="Drupal 8 (https://www.drupal.org)">
<meta name="MobileOptimized" content="width">
<meta name="HandheldFriendly" content="true">
<link rel="shortcut icon" href="http://example.com/core/misc/favicon.ico" type="image/vnd.microsoft.icon">
are still in <head>
. How can I remove them and add others instead in Drupal 8?