Why is magento 2 creating directives for media images using the admin url?
for example when i add an image on category page WYSIWYG it adds
<img src="{{media url="wysiwyg/image.jpg"}}" alt="" />
but then magento parses it for frontend and is like this
<img src="https://domain.co.uk/admin/cms/wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvQ29udmV5b3JfYmVsdHNfZmFzdF9kZWxpdmVyeS5qcGcifX0,/key/b67d0a8069ef28a8443e0bad6d912512704213d60e1d9021b1ec2b9dd34bf390/" alt="">
because its linking to admin the only way it will load on browser is if you are logged in to the admin. This also poses a security issue because it is disclosing the admin path on frontend.
I looked in vendor/magento/module-cms/Helper//Wysiwyg/images.php and looks like the function getImageHtmlDeclaration() generates this
public function getImageHtmlDeclaration($filename, $renderAsTag = false)
{
$fileurl = $this->getCurrentUrl() . $filename;
$mediaUrl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$mediaPath = str_replace($mediaUrl, '', $fileurl);
$directive = sprintf('{{media url="%s"}}', $mediaPath);
if ($renderAsTag) {
$html = sprintf('<img src="%s" alt="" />', $this->isUsingStaticUrlsAllowed() ? $fileurl : $directive);
} else {
if ($this->isUsingStaticUrlsAllowed()) {
$html = $fileurl; // $mediaPath;
} else {
$directive = $this->urlEncoder->encode($directive);
$html = $this->_backendData->getUrl('cms/wysiwyg/directive', ['___directive' => $directive]);
}
}
return $html;
}
I tried to use static urls for media but still no use so the only work around I can think of is to edit this function to use frontend url instead of backend/admin
any help on this would be very much appreciated :)
{{media url="wysiwyg/some-image.jpg"}}
format we have come to expect in Magento