{"id":207,"date":"2018-10-12T12:47:08","date_gmt":"2018-10-12T12:47:08","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/10\/12\/add-wysiwyg-editor-in-magento-2-admin-form\/"},"modified":"2025-05-22T17:17:17","modified_gmt":"2025-05-22T11:47:17","slug":"add-wysiwyg-editor-in-magento-2-admin-form","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-wysiwyg-editor-in-magento-2-admin-form\/","title":{"rendered":"How to Add WYSIWYG Editor in Magento 2 Admin Form"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WYSIWYG is an HTML editor to easily play with the content editing. WYSIWYG allows adding and formatting the content providing \u201c<em>What You See Is What You Get<\/em>&nbsp;\u201d view. One can see the end result that\u2019ll be displayed in the editing phase. Save yourself from the hassle of HTML programming for enhancing the appearance of frontend!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2, designed to be as user-friendly as possible, has WYSIWYG as the default editor.&nbsp;? But sometimes, you need to&nbsp;<em><strong>add WYSIWYG editor in Magento 2 Admin Form<\/strong><\/em>&nbsp;to collect data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adding WYSIWYG editor in Magento 2 backend eases the task of website development. What more luxury does a developer wish for?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, here\u2019s the code for you, ready to be implemented in the admin backend!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code to Add WYSIWYG Editor in Magento 2 Admin Form<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following code in your block file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected $wysiwygConfig;\n\npublic function __construct(\n    \\Magento\\Backend\\Block\\Template\\Context $context,\n    \\Magento\\Cms\\Model\\Wysiwyg\\Config $wysiwygConfig,\n    array $data = []\n) {\n    $this->wysiwygConfig = $wysiwygConfig;\n    parent::__construct($context, $data);\n}\n\n\nAdd field code \n\n$fieldset->addField(\n    'content',\n    'editor',\n    [\n        'name' => 'content',\n        'label' => __('Body'),\n        'title' => __('Body'),\n        'rows' => '5',\n        'cols' => '30',\n        'wysiwyg' => true,\n        'config' => $this->wysiwygConfig->getConfig(),\n        'required' => true\n    ]\n);\u200b\u200b\u200b\u200b\u200b\u200b\u200b<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the above method and the content editing is as easy as ABC!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WYSIWYG is an HTML editor to easily play with the content editing. WYSIWYG allows adding and formatting the content providing \u201cWhat You See Is What&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-207","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=207"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":15580,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/207\/revisions\/15580"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}