How do i get the base url in template.php?
None of the below works.
global $base_url; global $base_path; global $base_root;
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
You can use the
base_path() function which should always work.
To be honest though it just returns
$GLOBALS['base_path'] so your
global $base_path statement should work fine.
This does not directly answer the question, but seems relevant. If you're looking for the domain name / base url in order to combine it with the aliased path for a node, instead just get the absolute URL like this:
$absoluteurl = url('node/' . $nid, array('absolute' => TRUE)); // http://example.com/content/aliased_path
You can get it from
For more details see http://www.drupal4hu.com/node/310