getBaseUrl – Magento URL Path

When developing in Magento and playing arround with Magento Themes there is some functions you should know.

If you want to get the source url of an image, javascript or file, call one of this functions adding your own path at the end.

Under every function there is an example of the output value:

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>
Code language: HTML, XML (xml)

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); ?>
Code language: HTML, XML (xml)

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); ?>
Code language: HTML, XML (xml)

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); ?>
Code language: HTML, XML (xml)

<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?>
Code language: HTML, XML (xml)
  • Rick, great site and resource.

    Wondering if there is a source URL for Magento categories?

    <?php echo $this->getCategoryUrl($_category)?>
    Code language: HTML, XML (xml)

    My site is giving certain visitors an SSL Certificate error. Found that not all my links are converting to the secure https link. My host has verified the certificate placement. Your functions above have helped with converting most of my links to https.


    • Hi Eric,

      Thanks !

      Try this:

      <?php echo Mage::getModel("catalog/category")->load(5)->getUrl() ?>
      Code language: HTML, XML (xml)

      Let me know if it works 😉

  • Is there any method get the URL link for subsites/subdirectories



    • Have you tried to use the method above? I think it’s smart enough to know if you’re in the store1 or store2.

      Let me know if it works,


  • mahesh:

    No it isn’t.
    you should use:

    Code language: PHP (php)

Leave a Reply

Add <code> Some Code </code> by using this tags.