JDocumentHTML/addHeadLink
From Joomla! Documentation
Adds <link> tags to the head of the document
Contents |
Syntax
addHeadLink( $href, $relation, $relType, $attribs )
where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $href | strng | URL of the linked resource. | |
| $relation | string | Relation | |
| $relType | string | Relation type. May be 'rel' indicating a forward relation, or 'rev' for a reverse relation. | 'rel' |
| $attribs | array | Associative array of remaining attributes. |
Returns
void
Examples
Adding a link for an RSS feed to the document
To add a link for an RSS feed to the document, you could use:
$doc =& JFactory::getDocument(); $href = '/joomla/index.php?format=feed&type=rss'; $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); $doc->addHeadLink( $href, 'alternate', 'rel', $attribs );
When the document is rendered this will produce the following in the HTML <head> section:
<link href="/joomla/index.php?format=feed&type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
Adding a link to a CSS file to the document
To add a link to a CSS file to the document, you could use:
$doc =& JFactory::getDocument(); $href = 'index.php/other/css/mycss.css'; $attribs = array('type' => 'text/css'); $doc->addHeadLink( $href, 'stylesheet', 'rel', $attribs );
When the document is rendered this will produce the following in the HTML <head> section:
<link href="/index.php/other/css/mycss.css" rel="stylesheet" type="text/css" />
This is an alternative to using JDocument->addStyleSheet.
See also
Defined in
libraries/joomla/document/html/html.php
Importing
jimport( 'joomla.document.html.html' );
Source code 
function addHeadLink($href, $relation, $relType = 'rel', $attribs = array())
{
$attribs = JArrayHelper::toString($attribs);
$generatedTag = '<link href="'.$href.'" '.$relType.'="'.$relation.'" '.$attribs;
$this->_links[] = $generatedTag;
}
This is a test of the CodeExamples extension.
Chris Davenport 12:44, 3 January 2010 (EST)