Skip to content

Instantly share code, notes, and snippets.

@mrcgrtz
Created October 10, 2012 12:03
Show Gist options
  • Save mrcgrtz/3865185 to your computer and use it in GitHub Desktop.
Save mrcgrtz/3865185 to your computer and use it in GitHub Desktop.
Remove unneeded meta tags and links from Drupal 7
<?php
/**
* Override or insert variables into the HTML head.
*
* @param $head_elements
* An array of variables to pass to the HTML head.
*/
function MYTHEME_html_head_alter(&$head_elements) {
// remove unneeded metatags
$remove = array(
//'system_meta_content_type', // Content Type
'system_meta_generator', // Generator
'metatag_canonical', // Canonical Link
'rdf_node_title', // DC:Title
);
foreach ($remove as $item) {
if (isset($head_elements[$item])) {
unset($head_elements[$item]);
}
}
// remove unneeded links
$remove = array(
'/^drupal_add_html_head_link:shortcut icon:/', // Favicon
'/^drupal_add_html_head_link:shortlink:/', // Shortlink
);
foreach ($remove as $item) {
foreach (preg_grep($item, array_keys($head_elements)) as $key) {
unset($head_elements[$key]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment