function hook_html_head_alter

Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().

Elements available to be altered are only those added using drupal_add_html_head_link() or drupal_add_html_head(). CSS and JS files are handled using drupal_add_css() and drupal_add_js(), so the head links for those files will not appear in the $head_elements array.

Parameters

$head_elements: An array of renderable elements. Generally the values of the #attributes array will be the most likely target for changes.

Related topics

1 function implements hook_html_head_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

system_module_test_html_head_alter in drupal/core/modules/system/tests/modules/system_module_test/system_module_test.module
Implements hook_html_head_alter().
1 invocation of hook_html_head_alter()
drupal_get_html_head in drupal/core/includes/common.inc
Retrieves output to be displayed in the HEAD tag of the HTML page.

File

drupal/core/modules/system/system.api.php, line 3217
Hooks provided by Drupal core and the System module.

Code

function hook_html_head_alter(&$head_elements) {
  foreach ($head_elements as $key => $element) {
    if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {

      // I want a custom canonical URL.
      $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();
    }
  }
}