1 system.api.php | hook_html_head_alter(&$head_elements) |
Alter XHTML HEAD tags before they are rendered by backdrop_get_html_head().
Elements available to be altered are only those added using backdrop_add_html_head_link() or backdrop_add_html_head(). CSS and JS files are handled using backdrop_add_css() and backdrop_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
File
- core/
modules/ system/ system.api.php, line 3463 - Hooks provided by Backdrop 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'] = my_module_canonical_url();
}
}
}