Change {{media url=”wysiwyg/image.jpg”}} in Frontend in Custom Module – Magento2

magento2wysiwyg

I'm building a custom module, a very simple blog.
I already have everything working. The last thing I added, was de WYSIWYG image upload capability.

In the Admin, everything works fine. But in the fronted, I see the raw source code and the <img> tags are filled with: {{media url="wysiwyg/some_image.jpg"}}

If I navigate to /pub/media/wysiwyg/some_image.jpg, the jpg exists. But I can't figure out how to change this via some helper or function to get it right in the front end.

Best Answer

You can filter its using filter() function,

$content = 'This is test demo imgage, {{media url="wysiwyg/some_image.jpg"}}';
$om = \Magento\Framework\App\ObjectManager::getInstance();
$filterManager = $om->get('Magento\Cms\Model\Template\FilterProvider')->getPageFilter()->filter($content);
echo $filterManager;