Add different scripts to the header in Drupal (meta, link..)

Now let’s imagine that you want to use a generic function to add different types of scripts to your header: <meta> <link>? <script>. This is the solution I’ve found.

Important: it took me few hours until I realized.

second parameter of drupal_add_html_head must be a unique string, so I’ve used the path to the script because they are in different files inside a folder structure. but you can use a random generator, or maybe a better solution, but keep in mind that must be unique.

$script = "<meta name="google-site-verification" content="xxxxx" />";
drupal_add_html_head(array('#type' => 'markup', '#markup' => $script), "$script");
$script = "<link rel="apple-touch-icon-precomposed" href="" />";
drupal_add_html_head(array('#type' => 'markup', '#markup' => $script), "$script");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s