This is how you use the l function in Drupal 7

The Drupal l function should be used when printing out links.  This function correctly handles aliased paths and adds an active class attribute to links that point to the current page url.

This is how it looks with all its parameters being used.

The following code should only be used in drupal 7,  since the l function in drupal 6 has a different structure.

<?php
// Only the lines  with "!" are mandatory
echo l(
 t('Custom Text'),        // The text of the link !
 'url/long-url',          // The Url of the link !
  array(
    'attributes' => array( // The attributes: id, and css classes
      'id' => 'my-id',      
      'class' => array('firest-class', 'second-class')
      ),
    'query' => array(
      'q' => 'variable',  // will result in ?q=variable
    ),
    'fragment' => 'hashtag', // will result in #hashtag
    'html' => true,  // set this only if Custom Text contains safe html
  )
);
?>

Will result in:

<a class="first-class second-class" id="my-id" href="/url/long-url?q=variable#hashtag">Custom Text</a>

Notes:

  • I used the t function so the text can be translated later if needed.
  • By default html is set to false. This part ‘htm’ => ‘true’ is only needed if you would have had some html in custom text for example if the first line would have been like this.
 'Custom <span class="red">Text</span>'

Your feedback is appreciated! Thanks!