I'm building a multi language site but I'm facing a problem with an url. In my template i have the following print rule for an url <?php print $base_url.'/#project';?> The base url only prints http://www.codedesign.be/#project withouth the language selector. url is normal url/nl/#project or www.codedesign.be/fr/#project

2 Answers 2


You should use the url() function to create URLs.

Generates an internal or external URL.

This functions handles all complexity of creating an URL, including language prefix. url() handles exernal URLs too.

You can also use the l() function to create anchor tags:

Formats an internal or external URL link as an HTML anchor tag.

This function correctly handles aliased paths and adds an 'active' class attribute to links that point to the current page (for theming), so all internal links output by modules should be generated by this function if possible.

In your case you can use:

<?php print url('<front>', array('absolute' => TRUE, 'fragment' => 'project'));?>
  • 1
    Probably worth noting the OP will need to use <front> as the first param, and to have 'external' => TRUE in the options array to get the full URL
    – Clive
    Commented May 28, 2015 at 18:14
  • could you help me out how to write my php code then? Commented May 28, 2015 at 18:22
  • Answer updated with code but keep i mind that is better to code in the template.php than in .tpl files.
    – sanzante
    Commented May 28, 2015 at 18:52

If $base_url doesn't append the language, you may use this code

global $base_url;
global $language;
$url = $base_url."/".$language->name."/#peoject";
  • when I use this <?php global $base_url;global $language;$url = $base_url.$language->name."/#project";?> i get codedesign.be/nl/portfolio/droomevenementen and it needs to be codedesign.be/nl/#project Commented May 28, 2015 at 18:11
  • You can use the url() function @user2301868
    – Clive
    Commented May 28, 2015 at 18:12
  • @user2301868 I didn't get you! what is the problem with appending the language? But as clive said you can also use url() function.
    – M a m a D
    Commented May 28, 2015 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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