Skip to content

Instantly share code, notes, and snippets.

@jacine
Created May 19, 2011 03:19
Show Gist options
  • Save jacine/980120 to your computer and use it in GitHub Desktop.
Save jacine/980120 to your computer and use it in GitHub Desktop.
HTML5 Drupal 7 Tweaks
<?php
/**
* Implements hook_html_head_alter().
* - Simplify the meta charset element.
*/
function THEMENAME_html_head_alter(&$head_elements) {
$head_elements['system_meta_content_type']['#attributes'] = array(
'charset' => 'utf-8',
);
// Force IE to always run the latest rendering engine.
$head_elements['x-ua-compatible'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge,chrome=1',
),
);
}
/**
* Implements hook_preprocess_html_tag().
* - Remove the type attribute from the <script>, <style> and <link> elements.
* - Remove the CDATA comments from inline JavaScript and CSS.
*/
function THEMENAME_process_html_tag(&$vars) {
$element = &$vars['element'];
// Remove the "type" attribute.
if (in_array($element['#tag'], array('script', 'link', 'style'))) {
unset($element['#attributes']['type']);
// Remove CDATA comments.
if (isset($element['#value_prefix']) && ($element['#value_prefix'] == "\n<!--//--><![CDATA[//><!--\n" || $element['#value_prefix'] == "\n<!--/*--><![CDATA[/*><!--*/\n")) {
unset($element['#value_prefix']);
}
if (isset($element['#value_suffix']) && ($element['#value_suffix'] == "\n//--><!]]>\n" || $element['#value_suffix'] == "\n/*]]>*/-->\n")) {
unset($element['#value_suffix']);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment