Adds a LINK tag with distinct attributes to the page's HEAD.
This function can be called as long the HTML header hasn't been sent, which on normal pages is up through the preprocess step of theme('html'). Adding a link will overwrite a prior link with the exact same 'rel', 'href' and 'hreflang' attributes.
Parameters
$attributes: Associative array of element attributes including 'href' and 'rel'.
$header: Optional flag to determine if a HTTP 'Link:' header should be sent.
9 calls to drupal_add_html_head_link()
- common_test_html_head_link in modules/
simpletest/ tests/ common_test.module - Page callback.
- drupal_add_feed in includes/
common.inc - Adds a feed URL for the current page.
- node_page_view in modules/
node/ node.module - Menu callback: Displays a single node.
- openid_test_html_openid1 in modules/
openid/ tests/ openid_test.module - Menu callback; regular HTML page with OpenID 1.0 <link> element.
- openid_test_html_openid2 in modules/
openid/ tests/ openid_test.module - Menu callback; regular HTML page with OpenID 2.0 <link> element.
File
- includes/
common.inc, line 3000 - Common functions that many Drupal modules will need to reference.
Code
function drupal_add_html_head_link($attributes, $header = FALSE) {
$element = array(
'#tag' => 'link',
'#attributes' => $attributes,
);
$href = $attributes['href'];
if ($header) {
// Also add a HTTP header "Link:".
$href = '<' . $attributes['href'] . '>;';
unset($attributes['href']);
$element['#attached']['drupal_add_http_header'][] = array(
'Link',
$href . drupal_http_header_attributes($attributes),
TRUE,
);
}
drupal_add_html_head($element, 'drupal_add_html_head_link:' . $attributes['rel'] . ':' . (isset($attributes['hreflang']) ? "{$attributes['hreflang']}:" : '') . $href);
}