$base_url not working when in anchor link to theme folder e.g. this:

&lt;a href="&lt;?php echo $front_page; ?&gt;" title="&lt;?php echo t('Home');?&gt;" rel="home" id="logo"&gt;
        &lt;img src="http://localhost/jamesbondblog/sites/all/themes/jamestheme/images/logo.jpg"&gt;
&lt;/a&gt;


is working.

But this is not:

&lt;a href="&lt;?php echo $front_page; ?&gt;" title="&lt;?php echo t('Home');?&gt;" rel="home" id="logo"&gt;
        &lt;img src="&lt;?php echo $base_url; ?&gt;/sites/all/themes/jamestheme/images/logo.jpg"&gt;
&lt;/a&gt;


Can someone explain why?

I am using Drupal 7 and this code is in page.tpl.php
Try this...

In your themes template...

function YOURTHEME_preprocess_page(&amp;$variables) {
   global $base_url;
   $variables['base_url'] = $base_url;
}


In page template...

$base_url;