1. Using THEME.theme file
<?php
function theme_preprocess_html(&$variables) {
$metatag = [
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'x-ua-compatible',
'content' => 'ie=edge',
],
];
$variables['page']['#attached']['html_head'][] = [$metatag, 'x-ua-compatible'];
}
?>
2. Through Template file (html)
- You can directly add meta tags to <head>....</head> File: html.html.twig
3. Through Custom module (module_name_page_attachments)
module_name.module file
<?php
/**
* Implements hook_page_attachments().
*/
function module_name_page_attachments(array &$page) {
$metatag = [
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'x-ua-compatible',
'content' => 'ie=edge',
],
];
$page['#attached']['html_head'][] = [$metatag, 'x-ua-compatible'];
}
?>
4. Through drupal module
- you can use, Metatag module
5. How do I overwrite meta tags in Drupal8
- D8 has a new hook to achieve it : hook_page_attachments_alter().
- Add new comment
- 2160 views