Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding custom code to <head> in Drupal

Tags:

head

drupal

I'm trying to figure out where the <head> for all of the pages in Drupal is (I'm using Orange theme if it matters). I have to add analytics code into the <head>.

Inside which file would I find the <head>?

like image 495
AKor Avatar asked Feb 14 '11 02:02

AKor


1 Answers

Use drupal_set_html_head() by placing this in your themes template.php file. If the function MYTHEMENAME_preprocess_page() already exists insert what is inside the {closure} brackets below (before the $vars['head'] if that exists in it as well) :

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();
  }
}
like image 94
jpstrikesback Avatar answered Sep 17 '22 12:09

jpstrikesback