Round Rock / Austin, Texas
Drupal Web Developer

How to add the Viewport metatag for Drupal 7 sites

How to add the Viewport metatag for Drupal 7 sites

If you want your site to be responsive and mobile friendly, the Viewport metatag must be included in the <head> tag of your html.

To do this in Drupal 7, in your theme's template.php file add this code:

 

function YOURTHEMENAME_preprocess_html(&$vars) {
  $viewport = array(
   '#tag' => 'meta',
   '#attributes' => array(
     'name' => 'viewport',
     'content' => 'width=device-width, initial-scale=1, maximum-scale=1',
   ),
  );
  drupal_add_html_head($viewport, 'viewport');
}