Skip to content

Instantly share code, notes, and snippets.

@renebakx
Created December 16, 2020 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renebakx/897f3f7405740b7b1b1fb4308b7dad8e to your computer and use it in GitHub Desktop.
Save renebakx/897f3f7405740b7b1b1fb4308b7dad8e to your computer and use it in GitHub Desktop.
Writing the iframe tag at the top of your html.html.twig file in Drupal 8/9
<?php
function tagmanager_page_top(array &$page_top) {
if (FALSE === \Drupal::service('router.admin_context')->isAdminRoute()) {
$page_top['above'] = [
'#noscript' => true,
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'src' => sprintf('https://www.googletagmanager.com/ns.html?id=%s',$settings->get('gtm_code')),
'height' => 0,
'width' => 0,
'style' => "display:none;visibility:hidden"
]
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment