WYSIWYG editor in Magento 2 is an HTML editor that offers “what you see is what you get” functionality. It makes the task of adding, editing and formatting the content easier.
However, sometimes offering this editor gives unnecessary rights and features by allowing them to insert the variable and widget.
For example, the Magento marketplace has multiple users and vendors who can use the WYSIWYG editor from the admin panel. The super admin would not want them to use all the widgets but only allow designing with the editor. In such cases, one can use the below solution.
The default WYSIWYG editor in the Magento 2 is as shown here:

After implementing the below code, the WYSIWYG editor is as shown here:

Method to remove add variable & add widget from WYSIWYG editor in Magento 2:
1. Add below code in the system.xml file
<field id="description" translate="label comment" type="editor" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Description </label> <frontend_model>Vendor\Extension\Block\Adminhtml\Editor</frontend_model> </field>
2. Create new file Editor.php at Vendor\Extension\Block\Adminhtml folder
<?php namespace Vendor\Extension\Block\Adminhtml; use Magento\Backend\Block\Template\Context; use Magento\Cms\Model\Wysiwyg\Config as WysiwygConfig; class Editor extends \Magento\Config\Block\System\Config\Form\Field { public function __construct( Context $context, WysiwygConfig $wysiwygConfig, array $data = [] ) { $this->_wysiwygConfig = $wysiwygConfig; parent::__construct($context, $data); } protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $element->setWysiwyg(true); $confgiData = $this->wysiwygConfig->getConfig($element); $confgiData->setplugins([]); $confgiData->setadd_variables(0); $confgiData->setadd_widgets(0); $element->setConfig($confgiData); return parent::_getElementHtml($element); } }
That’s it.
Please share the solution with the Magento community via social media.
Thank you.