Adding Links in Drupal with the l() Function

In Drupal you should know that you never want to hardcode a local URL into your nodes or blocks. Firstly as your site expands the node may show from places you do not currently imagine thus breaking your paths. Secondly if you try to bypass this by using a full/direct URL, you are going to be up shit creek without a paddle when you migrate the URL. The link l() function should be used for adding links so that manipulations, like localization and URL determinations, can happen on the output.

Below are some of examples of creating links in drupal using the l() function:

  • internal link
    to make: Pancakes, the Sunday Stack
    use: NOTE: try to use node numbers
    <?php echo l('Pancakes, the Sunday Stacks', 'node/447', array("title"=>"Cooking Pancake")); ?>
  • external link
    to make:
    <?php echo l('', '', array("target"=>"_Blank", "rel"=>"nofollow")); ?>

Use your knowledge wisely. Peace out.


Post new comment

  • Allowed HTML tags: <em> <strong>
  • Lines and paragraphs break automatically.

More information about formatting options

Enter the characters shown in the image.