Processing... Please wait...

Product was successfully added to your shopping cart.

Magento 2 wysiwyg editor breaks images

Here is a Magento 2 wysiwig editor bug which is still present in the latest CE 2.1.5 (as of time of writing).


The problem description

Disclaimer: In the latest Magento CE 2.1.5 it seems to only affect category descriptions while in earlier versions it might affects product descriptions as well.

If you attempt to upload and add an image to any category description via wysiwyg editor:

Magento 2 Category Description wysiwyg editor Magento 2 Category Description wysiwyg editor

It is displayed on frontend as containing your admin url which is not only a security risk (revealing your backend path) but is also leading to a broken image if you are not logged in to admin:

Magento 2 broken image url Magento 2 broken image url

I discovered this bug while answering Magento Stackexchange question which leads me an open github issue.


The fix


Disclaimer: Once you implement the following fix you still need re-upload all saved category description images (if any).


The suggested fix would be to write an interceptor and add 'add_directives' => true to wysiwyg getConfig function.

Your etc/di.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Cms\Model\Wysiwyg\Config">
        <plugin name="add_wysiwyg_data" type="Vendor\Module\Plugin\WysiwygConfig" sortOrder="30" />


Your Vendor/Module/Plugin/WysiwygConfig.php file:


namespace Vendor\Module\Plugin;

class WysiwygConfig
    public function afterGetConfig($subject, \Magento\Framework\DataObject $config)
            'add_directives' => true,

        return $config;


Install it php bin/magento setup:upgrade and you are all set.

Here it is all packed up (not by me) as an extension.





Need help with a Magento site? Hire me!


Like the article? Share:


Other articles you might be interested in:

  1. 5 questions to ask to hire the right Magento 2 developer
  2. Magento image optimization in 3 easy steps
  3. Magento profiler not showing simple fix
  4. Make Magento 2.1.3 run on PHP 7.1.0


If you find this post interesting do not hesitate to sign up for our newsletter and join the 865 people who receive Magento news, tips and tricks regularly.

Thank You!