Back to Top

How to Get Base,Media,Link url in Magento 2

Updated 23 February 2024


To get the URL in magento2, you have to first create an instance of  \Magento\Framework\App\ObjectManager to get the current store:

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //instance of\Magento\Framework\App\ObjectManager
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface'); 
$currentStore = $storeManager->getStore();

To get the base URL:

$baseUrl = $currentStore->getBaseUrl();
//Output link will be like this:

To get media base URL:

$mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
//Media url output link will be like this:

To get the link base URL:

$linkUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
//Output link will be link this:

I hope this blog will help you with How to Get Base, Media, Link url in Magento 2. You may also check our wide range of best Magento 2 Extensions.

Searching for an experienced
Magento 2 Company ?
Find out More

Please reach out to our team via a support ticket if you have any queries.

Try this and if you have any queries then just comment below 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Praveen Chelumalla
  • Kamlesh Kumar Jha
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home