
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: //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 🙂
2 comments