Adding custom code to <head> in Drupal

I'm trying to figure out where <head>for all the pages in Drupal (I use the Orange theme, if that matters). I need to add analytics code in <head>.

Which file will I find inside <head>?

+5
source share
6 answers

If you look in the theme folder, you will see page.tpl.php, that is, a template for the site. You can add the code there most likely.

+3
source

drupal_set_html_head(), template.php . MYTHEMENAME_preprocess_page() , , {} ( $vars ['head'], ):

function MYTHEMENAME_preprocess_page(&$vars, $hook) {
  // say you wanted to add Google Webmaster Tools verification to homepage.
  if(drupal_is_front_page()) {
    drupal_set_html_head('<meta name="google-site-verification" content="[string from https://www.google.com/webmasters/verification/verification]" />');
    $vars['head'] = drupal_get_html_head();
  }
}
+6

template.php :

function your_theme_preprocess_html(&$variables) {  

                $appleIcon57px = array('#tag' => 'link', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/images/ICONE-57.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 163dpi)'),);
                drupal_add_html_head($appleIcon57px, 'apple-touch-icon57');

 }
+2
0

, css.

  • , , Structure- > Blocks .

  • , , , .

  • html . .

.

0

google, .

-1
source

All Articles