phtml Block file<\/a> create __construct function.<\/p>\nAdd to __construct in your class<\/p>\n
protected $_storeManager;<\/strong><\/p>\npublic function __construct(\\Magento\\Store\\Model\\StoreManagerInterface $storeManager)<\/strong><\/p>\n{<\/strong><\/p>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $this->_storeManager = $storeManager;<\/strong><\/p>\n}<\/strong><\/p>\nAdd new method in your class<\/p>\n
public function getMediaUrl($path)<\/strong><\/p>\n\u00a0\u00a0\u00a0 {<\/strong><\/p>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return $this->_storeManager->getStore()->getBaseUrl(\\Magento\\Framework\\UrlInterface::URL_TYPE_MEDIA) . $path;<\/strong><\/p>\n\u00a0\u00a0\u00a0 }<\/strong><\/p>\nCall in phtml<\/p>\n
<img src=”<?php echo $block->getMediaUrl(‘wysiwyg\/img.jpg’) ?>” \/><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"Using the code snippet lets understand how to get Media URL in Magento 2. For Getting Media URL Use Below code: $mediaUrl =$storeManager->getStore()->getBaseUrl(\\Magento\\Framework\\UrlInterface::URL_TYPE_MEDIA); Using the following method, you can get media URL in your template file, but without using object manager, you need to define Block file using the method construct() to define store Manager […]<\/p>\n","protected":false},"author":1,"featured_media":40883,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[],"class_list":{"0":"post-40867","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-magento-ecommerce"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/posts\/40867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/comments?post=40867"}],"version-history":[{"count":8,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/posts\/40867\/revisions"}],"predecessor-version":[{"id":57557,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/posts\/40867\/revisions\/57557"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/media\/40883"}],"wp:attachment":[{"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/media?parent=40867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/categories?post=40867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kinexmedia.com\/wp-json\/wp\/v2\/tags?post=40867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}