Friday, March 23, 2012

Adding viewport meta tag to Drupal 7 theme without overriding html.tpl.php

You can use drupal_add_html_head() for adding the viewport meta tag. In your theme template.php file, you can call hook_page_alter() for embeding meta.


function YOURTHEMENAME_page_alter($page) {
//
$viewport = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' =>  'viewport',
'content' =>  'width=device-width, initial-scale=1, maximum-scale=1'
)
);
drupal_add_html_head($viewport, 'viewport');
}