I think that I need to use the l() function as seen here: How do I get the absolute URL when using l()?

I just need a bit more clarification. What's the best way to create links on pages? I would like to link them correctly so that if my domain changes then the link will be updated (for example going from a local host to an online host). Let me also know if this is not the best way to do it.

I guess I need to know what would go into HTML tag and then also do I need to place any code anywhere else?


You should use the l() and url() functions as specified in the answer to the question you link to. Those are core Drupal functions so nothing else is needed.

  • I put the link in my page.tpl.php file and it worked perfectly, but when I tried putting that same link in a block it wouldn't. Any ideas why? My Link: <?php l(t('About'), 'node/123', array('absolute' => TRUE));?> – Dan Nov 25 '12 at 22:47
  • Ah, I figured it out. In the block prefs I need to list it as having "PHP code" not HTML. Thanks! – Dan Nov 25 '12 at 22:56
  • 1
    That is correct. Although you should try to avoid using the PHP input filter if possible. – enzipher Nov 26 '12 at 0:32
  • how would you recommend that I add links in blocks then? Is there a better way? – Dan Nov 26 '12 at 1:53
  • 1
    It really depends on the situation. You can make a custom module which provide the block, or you can override the block with a template file. You can use input filter such as Path Filter (D6) or Pathologic (D7). On the other hand, if it's just one link in a block perhaps it's not a big deal to make a static link to /mypage. – enzipher Nov 26 '12 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.