Magento Get URL on php and phtml pages -Magento URL Function

With the below code you can get all the Magento URL related methods like Base URL, Skin URL, Unsecure Skin URL, Media URL, Js URL, Store URL, Current URL, Store Page URL, Store Page URL without slash

1. Get Base Url :

[sourcecode language=”php”]Mage::getBaseUrl();[/sourcecode]

2. Get Skin Url :

[sourcecode language=”php”]Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);[/sourcecode]

(a) Unsecure Skin Url :

[sourcecode language=”php”]$this->getSkinUrl(‘images/imagename.jpg’);[/sourcecode]

(b) Secure Skin Url :
[sourcecode language=”php”]$this->getSkinUrl(‘images/imagename.gif’, array(‘_secure’=>true));[/sourcecode]

3. Get Media Url :

[sourcecode language=”php”]Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);[/sourcecode]

4. Get Js Url :

[sourcecode language=”php”]Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);[/sourcecode]

5. Get Store Url :

[sourcecode language=”php”]Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);[/sourcecode]

6. Get Current Url
[sourcecode language=”php”]Mage::helper(‘core/url’)->getCurrentUrl();[/sourcecode]

Get Url in cms pages or static blocks

1. Get Base Url :

[sourcecode language=”php”]{{store url=""}}[/sourcecode]

2. Get Skin Url :

[sourcecode language=”php”]{{skin url=’images/imagename.jpg’}}[/sourcecode]

3. Get Media Url :
[sourcecode language=”php”]{{media url=’/imagename.jpg’}}[/sourcecode]

4. Get Store Page Url :

[sourcecode language=”php”]{{store url=’contacts’}}[/sourcecode]

5. Get Store Page URL Direct link without “/”

[sourcecode language=”php”]{{store direct_url="my-page.html"}}[/sourcecode]

About the author: ShareSoftAdmin

Leave a Reply

Your email address will not be published.