Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

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

Let’s dive into How to Get URL in Magento 2 and understand the easiest ways to fetch URLs programmatically.

To get the URL in magento 2, 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:
//http://magento2.webkul.com/marketplace

To get media base URL:

$mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
//Media url output link will be like this:
//http://magento2.webkul.com/marketplace/pub/media

To get the link base URL:

$linkUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
//Output link will be link this:
//http://magento2.webkul.com/marketplace

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.

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*


2 comments

  • 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