function theme_link

7.x theme_link($variables)

Returns HTML for a link.

All Drupal code that outputs a link should call the l() function. That function performs some initial preprocessing, and then, if necessary, calls theme('link') for rendering the anchor tag.

To optimize performance for sites that don't need custom theming of links, the l() function includes an inline copy of this function, and uses that copy if none of the enabled modules or the active theme implement any preprocess or process functions or override this theme implementation.


array $variables: An associative array containing the keys:

  • text: The text of the link.
  • path: The internal path or external URL being linked to. It is used as the $path parameter of the url() function.
  • options: (optional) An array that defaults to empty, but can contain:
    • attributes: Can contain optional attributes:

      • class: must be declared in an array. Example: 'class' => array('class_name1','class_name2').
      • title: must be a string. Example: 'title' => 'Example title'
      • Others are more flexible as long as they work with drupal_attributes($variables['options']['attributes]).
    • html: Boolean flag that tells whether text contains HTML or plain text. If set to TRUE, the text value will not be sanitized so the calling function must ensure that it already contains safe HTML.

The elements $variables['options']['attributes'] and $variables['options']['html'] are used in this function similarly to the way that $options['attributes'] and $options['html'] are used in l(). The link itself is built by the url() function, which takes $variables['path'] and $variables['options'] as arguments.

See also



Related topics

1 string reference to 'theme_link'
l in drupal/includes/
Formats an internal or external URL link as an HTML anchor tag.
3 theme calls to theme_link()
book_block_view in drupal/modules/book/book.module
Implements hook_block_view().
dblog_overview in drupal/modules/dblog/
Page callback: Displays a listing of database log messages.
l in drupal/includes/
Formats an internal or external URL link as an HTML anchor tag.
98 string references to the theme hook from theme_link()

Note: this list is generated by looking for the string for this theme hook, so it may include some references that are not actually using this theme hook.

AggregatorUpdatePathTestCase::testAggregatorUpdate in drupal/modules/simpletest/tests/upgrade/update.aggregator.test
Tests that the aggregator.module update is successful.
aggregator_aggregator_parse in drupal/modules/aggregator/
Implements hook_aggregator_parse().
aggregator_aggregator_process in drupal/modules/aggregator/
Implements hook_aggregator_process().
aggregator_element_data in drupal/modules/aggregator/
Performs an action when data is encountered.
aggregator_element_start in drupal/modules/aggregator/
Performs an action when an opening tag is encountered.

... See full list


drupal/includes/, line 1737
The theme system, which controls the output of Drupal.


function theme_link($variables) {
  return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>';