Magento – Link to Base URL within Static Blocks and PHP

An extremely useful call in Magento is the ability to link to your base URL, without having to do hard-coded links, such as “/contact-us” or something similar. I’ll display two ways to do this – one way is to link to your store’s base url within static blocks, and one way is to do it within your PHP code (which cannot be used in Static Blocks).

Link to Base URL inside Static Block

Inside of your static block, you can simply do:

<a href='{{store url=""}}'>This links to your Base URL</a>

Link to Base URL inside of your PHP code

One way to find the URL to your base url is to do the following:

$_getBase = Mage::app()->getStore()->getBaseUrl();
<a href="<?php echo $_getBase; ?>">Link</a> 

Short and sweet!

Posted in PHP