function amp_html_head_alter in Accelerated Mobile Pages (AMP) 7
Implements hook_html_head_alter().
File
- ./
amp.module, line 1590
Code
function amp_html_head_alter(&$head_elements) {
// Make canonical links absolute for AMP content.
if (amp_is_amp_request()) {
foreach ($head_elements as $key => &$tag) {
if (strpos($key, 'drupal_add_html_head_link:canonical:') === 0) {
if (isset($tag['#attributes']['href'])) {
$amphtml_url = $tag['#attributes']['href'];
// Double check that the URL is relative.
if ($amphtml_url == drupal_get_normal_path($amphtml_url)) {
$absolute_url = url($amphtml_url, array(
'absolute' => TRUE,
));
$tag['#attributes']['href'] = $absolute_url;
}
}
}
}
}
}