link_tag()

link_tag([$href = ''[, $rel = 'stylesheet'[, $type = 'text/css'[, $title = ''[, $media = ''[, $index_page = FALSE]]]]]])

Parameters:
  • $href (string) – What are we linking to
  • $rel (string) – Relation type
  • $type (string) – Type of the related document
  • $title (string) – Link title
  • $media (string) – Media type
  • $index_page (bool) – Whether to treat $src as a routed URI string
Returns:

HTML link tag

Return type:

string

Lets you create HTML <link /> tags. This is useful for stylesheet links, as well as other links. The parameters are href, with optional rel, type, title, media and index_page.

index_page is a boolean value that specifies if the href should have the page specified by $config['index_page'] added to the address it creates.

Example:

echo link_tag('css/mystyles.css');
// gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />

Further examples:

echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');
// <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />

echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
// <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />

Additionally, an associative array can be passed to the link() function for complete control over all attributes and values:

$link = array(
        'href'  => 'css/printer.css',
        'rel'   => 'stylesheet',
        'type'  => 'text/css',
        'media' => 'print'
);

echo link_tag($link);
// <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
doc_CodeIgniter
2016-10-15 16:32:28
Comments
Leave a Comment

Please login to continue.