{"id":3131,"date":"2021-01-09T17:27:22","date_gmt":"2021-01-10T00:27:22","guid":{"rendered":"https:\/\/blocksylaunch.click\/documentation\/?p=3131"},"modified":"2021-01-09T17:27:22","modified_gmt":"2021-01-10T00:27:22","slug":"how-to-create-a-custom-field-for-a-divi-builder-module","status":"publish","type":"post","link":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/","title":{"rendered":"How To Create a Custom Field For a Divi Builder Module"},"content":{"rendered":"<blockquote><p><strong>Note:<\/strong> This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.<\/p><\/blockquote>\n<h2>Custom Fields for Divi Module Settings<\/h2>\n<p>Creating a custom field for a Divi module is similar to <a href=\"https:\/\/blocksylaunch.click\/documentation\/developers\/divi-module\/how-to-create-a-divi-builder-module\/\" rel=\"noopener noreferrer\" target=\"_blank\">creating a custom Divi module<\/a> in the Divi Builder. Both methods require some Javascript, HTML, &#038; CSS code. However, to create a custom field for a module, there is no need for any PHP because you don\u2019t need to write a PHP class to render the HTML output on the frontend. The main component needed is a ReactJS component class that handles rendering the field inside of the Divi Builder. Then you can define the custom field on your module definition.<\/p>\n<p>In this tutorial, you\u2019ll learn how to create custom fields for a Divi Builder module that will be fully functional in the builder.<\/p>\n<h2>Getting Started<\/h2>\n<p>Keep in mind. Custom Divi Builder fields must be implemented within a theme, child-theme, or Divi Extension. In this tutorial, we\u2019re going to create a custom field for a custom module in a Divi Extension.<\/p>\n<p>Also, this tutorial is a continuation of previous tutorials that have a specific setup already in place.<\/p>\n<p>If you haven\u2019t already done so, go ahead and do the following before you start this tutorial:<\/p>\n<ol>\n<li><a href=\"https:\/\/blocksylaunch.click\/documentation\/divi\/create-divi-extension\" rel=\"noopener noreferrer\" target=\"_blank\">Create a Divi Extension<\/a><\/li>\n<li><a href=\"https:\/\/blocksylaunch.click\/documentation\/developers\/divi-module\/how-to-create-a-divi-builder-module\/\" rel=\"noopener noreferrer\" target=\"_blank\">Create a Custom Module<\/a>.<\/li>\n<\/ol>\n<p>Once done, you are ready to continue.<\/p>\n<h3>Run Yarn<\/h3>\n<p>Before we can test our custom field later on in the Divi Builder we&#8217;ll need to compile the JSX code into regular JavaScript. To do that, we need to run <code>yarn<\/code>. To do this, simply run the following command inside your plugin\u2019s directory:<\/p>\n<pre>yarn start<\/pre>\n<p>IMPORTANT: Be sure that <code>yarn start<\/code> is running in the root folder of your plugin. Furthermore, you should keep <code>yarn start<\/code> running as you develop so that the files continue to compile successfully.<\/p>\n<h3>Upgrading Divi Scripts<\/h3>\n<p>Custom Divi Builder Fields is a new feature and only available on divi-scripts version 1.0.2 above. So, if you want to add custom field on your existing extension, please upgrade your divi-scripts to version 1.0.2. You can do this by changing divi-scripts version on your  <code>package.json<\/code> located at at the root of your extension directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg\" alt=\"custom fields for divi builder modules\" width=\"880\" height=\"423\" class=\"with-border aligncenter size-full wp-image-3158\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg 880w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1-300x144.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1-768x369.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<p>Then run <code>yarn install<\/code> to update. You can also find a custom field example on this documentation <a href=\"https:\/\/github.com\/elegantthemes\/create-divi-extension\/tree\/master\/packages\/divi-scripts\/template\/includes\" rel=\"noopener noreferrer\" target=\"_blank\">here<\/a>.<\/p>\n<h2>Update Field Directory and File Names<\/h2>\n<p>We\u2019ll get to update the code in our files in a bit. But before we can do that, we need to change the default directory and file names for our new custom field.<\/p>\n<p>Look inside your extension\u2019s directory and locate the example custom field located at <code>\/includes\/fields\/Input\/Input.jsx<\/code>. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/input-file-location.jpg\" alt=\"custom fields for divi builder modules\" width=\"880\" height=\"318\" class=\"with-border aligncenter size-full wp-image-3138\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/input-file-location.jpg 880w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/input-file-location-300x108.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/input-file-location-768x278.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<p>We\u2019ll use this as a starting point to create a custom input field. <\/p>\n<p>First, rename the <code>Input<\/code> directory to <code>SimpleInput<\/code>. <\/p>\n<p>Inside the directory (now named <code>SimpleInput<\/code>), rename the file <code>Input.jsx<\/code> to <code>SimpleInput.jsx<\/code>. <\/p>\n<p>The path to the file should now be <code>includes\/fields\/SimpleInput\/SimpleInput.jsx<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/jsx-path.jpg\" alt=\"how to create a custom field for a Divi Builder Module\" width=\"815\" height=\"354\" class=\"with-border aligncenter size-full wp-image-3161\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/jsx-path.jpg 815w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/jsx-path-300x130.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/jsx-path-768x334.jpg 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/p>\n<h2>Update the Field File<\/h2>\n<p>Open the <code>SimpleInput.jsx<\/code> file and edit it as follows:<\/p>\n<h3>Update the React Component Class<\/h3>\n<p>For our custom field to be available and fully functional inside the Divi Builder we must create a <a href=\"https:\/\/reactjs.org\/docs\/react-component.html\" rel=\"noopener noreferrer\" target=\"_blank\">React Component<\/a> class that handles the rendering of our custom field based on its <code>props<\/code>.<\/p>\n<p>By default, the component class is named <code>Input<\/code>. Change the name of the class <code>Input<\/code> to <code>SimpleInput<\/code>.  <\/p>\n<p>Then change the name <code>Input<\/code> to <code>SimpleInput<\/code> at the bottom of the file to reflect the new name of our component class in order to be exported for use.<\/p>\n<p>Also make sure to update the slug, input id, and input className to reflect the name of the new field.<\/p>\n<p>(NOTE: Depending on the prefix id you chose when setting up your Divi Extension, you may see different names for the static slug, input id, input class, etc. This example has the prefix <code>simp<\/code> which was chosen when creating the Divi Extension.)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-input-file.jpg\" alt=\"custom fields for divi builder modules\" width=\"880\" height=\"1177\" class=\"with-border aligncenter size-full wp-image-3144\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-input-file.jpg 880w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-input-file-224x300.jpg 224w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-input-file-766x1024.jpg 766w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-input-file-768x1027.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<p>Here is an example of what the code should look like after the change has been made:<\/p>\n<pre class=\"brush: jscript; title: SimpleInput.jsx; notranslate\" title=\"SimpleInput.jsx\">\r\n\/\/ External Dependencies\r\nimport React, { Component } from 'react';\r\n\r\n\/\/ Internal Dependencies\r\nimport '.\/style.css';\r\n\r\nclass SimpleInput extends Component {\r\n\r\n  static slug = 'simp_simple_input';\r\n\r\n  \/**\r\n   * Handle input value change.\r\n   *\r\n   * @param {object} event\r\n   *\/\r\n  _onChange = (event) =&gt; {\r\n    this.props._onChange(this.props.name, event.target.value);\r\n  }\r\n\r\n  render() {\r\n    return(\r\n      &lt;input\r\n        id={`simp-simple-input-${this.props.name}`}\r\n        name={this.props.name}\r\n        value={this.props.value}\r\n        type='text'\r\n        className='simp-simple-input'\r\n        onChange={this._onChange}\r\n        placeholder='Your text here ...'\r\n      \/&gt;\r\n    );\r\n  }\r\n}\r\n\r\nexport default SimpleInput;\r\n<\/pre>\n<p>The <code>_onChange()<\/code> prop is a method handler to save or remove the field setting\u2019s value. It passes 2 parameters.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/parameters.jpg\" alt=\"custom fields for divi builder modules\" width=\"880\" height=\"258\" class=\"with-border aligncenter size-full wp-image-3139\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/parameters.jpg 880w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/parameters-300x88.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/parameters-768x225.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<p>The first parameter is the field setting\u2019s name. You can use <code>name<\/code> prop here because it\u2019s already supplied with the correct field name based on the current active tab mode. For example: when you are editing the Title option in Tablet tab mode, the field\u2019s name generated is <code>title_tablet<\/code>. The second parameter is the field setting value that you want to save. <\/p>\n<p>The <strong>field setting type<\/strong> is actually a third parameter that is automatically defined with the current field type prop. So we don\u2019t have to include that parameter with the other 2.<\/p>\n<h2>Update the index.js file for the Custom Field<\/h2>\n<p>Next, let\u2019s update the import and export statements in the <strong>index.js<\/strong> file located at <code>\/includes\/fields\/index.js<\/code>. To do this, open to edit the <strong>index.js<\/strong> file.<\/p>\n<p>Replace all instances of the name for the class and directory (which is <code>Input<\/code> by default) to the new name <code>SimpleInput<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-index.jpg\" alt=\"custom fields for divi builder modules\" width=\"880\" height=\"298\" class=\"with-border aligncenter size-full wp-image-3143\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-index.jpg 880w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-index-300x102.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-index-768x260.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<p>Here is an example of the final code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport SimpleInput from '.\/SimpleInput\/SimpleInput';\r\n\r\nexport default &#x5B;SimpleInput];\r\n<\/pre>\n<h2>Custom Field CSS Styles<\/h2>\n<p>Styles for our custom field can be defined using the <strong>style.css<\/strong> file in its directory located at <code>\/includes\/fields\/SimpleInput\/style.css<\/code>. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/style-path.jpg\" alt=\"how to create a custom field for a Divi Builder Module\" width=\"843\" height=\"354\" class=\"with-border aligncenter size-full wp-image-3162\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/style-path.jpg 843w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/style-path-300x126.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/style-path-768x323.jpg 768w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/p>\n<p>Our custom field is only a basic input element that comes with default builder styling. For now, let\u2019s change the default class selector to <code>.simp-simple-input<\/code> (rendered in <strong>SimpleInput.jsx<\/strong>) throughout the style.css file:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\ninput.simp-simple-input {\r\n  background: #f1f5f9;\r\n  max-height: 30px;\r\n  border: 0;\r\n  border-radius: 3px;\r\n  padding: 7px 10px;\r\n  box-sizing: border-box;\r\n  transition: background 200ms ease;\r\n  color: #4C5866;\r\n  font-family: 'Open Sans', Helvetica, Roboto, Arial, sans-serif;\r\n  font-size: 13px;\r\n  font-weight: 600;\r\n  line-height: normal;\r\n  display: block;\r\n  width: 100%;\r\n}\r\n\r\ninput.simp-simple-input:focus {\r\n  background: #e6ecf2;\r\n}\r\n\r\ninput.simp-simple-input::-webkit-input-placeholder {\r\n  color: #98a7b8;\r\n}\r\n\r\ninput.simp-simple-input:-moz-placeholder {\r\n  color: #98a7b8;\r\n}\r\n\r\ninput.simp-simple-input::-moz-placeholder {\r\n  color: #98a7b8;\r\n}\r\n\r\ninput.simp-simple-input:-ms-input-placeholder {\r\n  color: #98a7b8;\r\n}\r\n\r\ninput.simp-simple-input&#x5B;readonly] {\r\n  background: #ffffff !important;\r\n  border: 1px solid #eaedf0 !important;\r\n  cursor: not-allowed;\r\n}\r\n<\/pre>\n<h2>Field Definition<\/h2>\n<p>To use our custom field, we need to define it on the module definition of our intended module. For this example, let\u2019s add it to the Simple Header module we created in <a href=\"https:\/\/blocksylaunch.click\/documentation\/developers\/divi-module\/how-to-create-a-divi-builder-module\/\" rel=\"noopener noreferrer\" target=\"_blank\">the previous tutorial<\/a>. <\/p>\n<p>Open the <strong>SimpleHeader.php<\/strong> file located at <code>\/includes\/modules\/SimpleHeader\/SimpleHeader.php<\/code>. <\/p>\n<p>Then add the code to define the custom field. Don\u2019t forget to use  <code>simp_simple_input<\/code> as the field type.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/define-field.jpg\" alt=\"custom fields for divi builder modules\" width=\"952\" height=\"511\" class=\"with-border aligncenter size-full wp-image-3136\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/define-field.jpg 952w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/define-field-300x161.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/define-field-768x412.jpg 768w\" sizes=\"auto, (max-width: 952px) 100vw, 952px\" \/><\/p>\n<p>The final code will look like this:<\/p>\n<pre class=\"brush: php; highlight: [26,27,28,29,30,31,32]; title: ; notranslate\" title=\"\">\r\n\r\nclass SIMP_SimpleHeader extends ET_Builder_Module {\r\n\r\n\tpublic $slug       = 'simp_simple_header';\r\n\tpublic $vb_support = 'on';\r\n\r\n\tpublic function init() {\r\n\t\t$this-&gt;name = esc_html__( 'Simple Header', 'simp-simple-extension' );\r\n\t}\r\n\r\n\tpublic function get_fields() {\r\n\t\treturn array(\r\n\t\t\t'heading'     =&gt; array(\r\n\t\t\t\t'label'           =&gt; esc_html__( 'Heading', 'simp-simple-extension' ),\r\n\t\t\t\t'type'            =&gt; 'text',\r\n\t\t\t\t'option_category' =&gt; 'basic_option',\r\n\t\t\t\t'description'     =&gt; esc_html__( 'Input your desired heading here.', 'simp-simple-extension' ),\r\n\t\t\t\t'toggle_slug'     =&gt; 'main_content',\r\n\t\t\t),\r\n\t\t\t'content'     =&gt; array(\r\n\t\t\t\t'label'           =&gt; esc_html__( 'Content', 'simp-simple-extension' ),\r\n\t\t\t\t'type'            =&gt; 'tiny_mce',\r\n\t\t\t\t'option_category' =&gt; 'basic_option',\r\n\t\t\t\t'description'     =&gt; esc_html__( 'Content entered here will appear below the heading text.', 'simp-simple-extension' ),\r\n\t\t\t\t'toggle_slug'     =&gt; 'main_content',\r\n\t\t\t),\r\n\t\t\t'field'       =&gt; array(\r\n\t\t\t\t'label'           =&gt; esc_html__( 'Custom Field', 'simp-simple-extension' ),\r\n\t\t\t\t'type'            =&gt; 'simp_simple_input',\r\n\t\t\t\t'option_category' =&gt; 'basic_option',\r\n\t\t\t\t'description'     =&gt; esc_html__( 'Text entered here will appear inside the module.', 'simp-simple-extension' ),\r\n\t\t\t\t'toggle_slug'     =&gt; 'main_content',\r\n\t\t\t),\r\n\t\t);\r\n\t}\r\n\r\n\tpublic function render( $unprocessed_props, $content = null, $render_slug ) {\r\n\t\treturn sprintf(\r\n\t\t\t'&lt;h1 class=&quot;simp-simple-header-heading&quot;&gt;%1$s&lt;\/h1&gt;\r\n\t\t\t&lt;div&gt;%2$s&lt;\/div&gt;',\r\n\t\t\tesc_html( $this-&gt;props&#x5B;'heading'] ),\r\n\t\t\t$this-&gt;props&#x5B;'content']\r\n\t\t);\r\n\t}\r\n}\r\n\r\nnew SIMP_SimpleHeader;\r\n<\/pre>\n<p>The properties that were added to the field are only the required properties you need to define. But you can add more properties to use on the custom field if you want. For instance, you can add both responsive and hover options for your custom field as well.<\/p>\n<h2>Divi Builder and Frontend Output<\/h2>\n<p>Our field definition is ready. We just need to update the  <code>render()<\/code> method so that it will display the custom field value. Let\u2019s start with the  <code>render()<\/code> method on the module PHP class.<\/p>\n<p>Open the <code>SimpleHeader.php<\/code> file and update the <code>render()<\/code> method as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-php-1.jpg\" alt=\"how to create a custom field for a Divi Builder Module\" width=\"763\" height=\"286\" class=\"with-border aligncenter size-full wp-image-3183\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-php-1.jpg 763w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-php-1-300x112.jpg 300w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/p>\n<p>The final code should look like this:<\/p>\n<pre class=\"brush: php; highlight: [36,37,38,39,40,41,42,43,44,45]; title: ; notranslate\" title=\"\">\r\n\r\nclass SIMP_SimpleHeader extends ET_Builder_Module {\r\n\r\n\tpublic $slug       = 'simp_simple_header';\r\n\tpublic $vb_support = 'on';\r\n\r\n\tpublic function init() {\r\n\t\t$this-&gt;name = esc_html__( 'Simple Header', 'simp-simple-extension' );\r\n\t}\r\n\r\n\tpublic function get_fields() {\r\n\t\treturn array(\r\n\t\t\t'heading'     =&gt; array(\r\n\t\t\t\t'label'           =&gt; esc_html__( 'Heading', 'simp-simple-extension' ),\r\n\t\t\t\t'type'            =&gt; 'text',\r\n\t\t\t\t'option_category' =&gt; 'basic_option',\r\n\t\t\t\t'description'     =&gt; esc_html__( 'Input your desired heading here.', 'simp-simple-extension' ),\r\n\t\t\t\t'toggle_slug'     =&gt; 'main_content',\r\n\t\t\t),\r\n\t\t\t'content'     =&gt; array(\r\n\t\t\t\t'label'           =&gt; esc_html__( 'Content', 'simp-simple-extension' ),\r\n\t\t\t\t'type'            =&gt; 'tiny_mce',\r\n\t\t\t\t'option_category' =&gt; 'basic_option',\r\n\t\t\t\t'description'     =&gt; esc_html__( 'Content entered here will appear below the heading text.', 'simp-simple-extension' ),\r\n\t\t\t\t'toggle_slug'     =&gt; 'main_content',\r\n\t\t\t),\r\n\t\t\t'field'       =&gt; array(\r\n\t\t\t\t'label'           =&gt; esc_html__( 'Custom Field', 'simp-simple-extension' ),\r\n\t\t\t\t'type'            =&gt; 'simp_simple_input',\r\n\t\t\t\t'option_category' =&gt; 'basic_option',\r\n\t\t\t\t'description'     =&gt; esc_html__( 'Text entered here will appear inside the module.', 'simp-simple-extension' ),\r\n\t\t\t\t'toggle_slug'     =&gt; 'main_content',\r\n\t\t\t),\r\n\t\t);\r\n\t}\r\n\r\n\tpublic function render( $unprocessed_props, $content = null, $render_slug ) {\r\n\t\treturn sprintf(\r\n\t\t\t'&lt;h1 class=&quot;simp-simple-header-heading&quot;&gt;%1$s&lt;\/h1&gt;\r\n\t\t\t&lt;div&gt;%2$s&lt;\/div&gt;\r\n\t\t\t&lt;p&gt;%3$s&lt;\/p&gt;',\r\n\t\t\tesc_html( $this-&gt;props&#x5B;'heading'] ),\r\n\t\t\t$this-&gt;props&#x5B;'content'],\r\n\t\t\t$this-&gt;props&#x5B;'field']\r\n\t\t);\r\n\t}\r\n}\r\n\r\nnew SIMP_SimpleHeader;\r\n<\/pre>\n<p>Now, let\u2019s edit the  <code>render()<\/code> method of the React component and make it produce the same output that we defined in our PHP  <code>render()<\/code> method.<\/p>\n<p>Open the <code>SimpleHeader.jsx<\/code> file and update the <code>render()<\/code> method as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-jsx.jpg\" alt=\"how to create a custom field for a Divi Builder Module\" width=\"774\" height=\"374\" class=\"with-border aligncenter size-full wp-image-3184\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-jsx.jpg 774w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-jsx-300x145.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/render-jsx-768x371.jpg 768w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/p>\n<p>The final code should look like this:<\/p>\n<pre class=\"brush: jscript; highlight: [19,20,21]; title: ; notranslate\" title=\"\">\r\n\/\/ External Dependencies\r\nimport React, { Component, Fragment } from 'react';\r\n\r\n\/\/ Internal Dependencies\r\nimport '.\/style.css';\r\n\r\n\r\nclass SimpleHeader extends Component {\r\n\r\n  static slug = 'simp_simple_header';\r\n\r\n  render() {\r\n    return (\r\n      &lt;Fragment&gt;\r\n        &lt;h1 className=&quot;simp-simple-header-heading&quot;&gt;{this.props.heading}&lt;\/h1&gt;\r\n        &lt;div&gt;\r\n          {this.props.content()}\r\n        &lt;\/div&gt;\r\n        &lt;p&gt;\r\n          {this.props.field}\r\n        &lt;\/p&gt;\r\n      &lt;\/Fragment&gt;\r\n    );\r\n  }\r\n}\r\n\r\nexport default SimpleHeader;\r\n<\/pre>\n<p>Here you can see how the output of the <code>render()<\/code> method of the php file corresponds to the output of the <code>render()<\/code> method of the php file which now includes the new field wrapped in a <code>p<\/code> tag.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/match-renders.jpg\" alt=\"how to create a custom field for a Divi Builder Module\" width=\"1200\" height=\"309\" class=\"with-border aligncenter size-full wp-image-3185\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/match-renders.jpg 1200w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/match-renders-300x77.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/match-renders-1024x264.jpg 1024w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/12\/match-renders-768x198.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h3>Add Selectors if Needed<\/h3>\n<p>Wrapping the new field output with a <code>p<\/code> tag makes sense here because we are interested in simple text output. This also is a good opportunity to add your own custom selectors (CSS ID, CSS Class) to the <code>p<\/code> tag for your own needs. Just make sure you add the same selectors to the output of the <code>render()<\/code> method of the PHP file and the JSX file.<\/p>\n<h2>Testing Your Custom Fields<\/h2>\n<p>If you already have <code>yarn start<\/code> running as we suggested in the first step, you can now launch the Divi Builder and check out your Simple Input field!<\/p>\n<p>If not, before we can test our custom field in the Divi Builder we need to compile the JSX code into regular JavaScript. To do that, simply run the following command inside your plugin\u2019s directory:<\/p>\n<pre>yarn start<\/pre>\n<p>As a reminder, you should keep <code>yarn start<\/code> running as you continue to edit your files so that the files continue to compile successfully.<\/p>\n<p>To test out the custom field, go to your Divi site and open the settings of the custom Simple Header Module. The new Custom Field will be under the content tab.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/final-result.jpg\" alt=\"custom fields for divi builder modules\" width=\"880\" height=\"783\" class=\"with-border aligncenter size-full wp-image-3137\" srcset=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/final-result.jpg 880w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/final-result-300x267.jpg 300w, https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/final-result-768x683.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<h2>Wrapping up<\/h2>\n<p>When you are finished development, remember to stop <code>yarn start<\/code> from running in your terminal (hitting <strong>ctrl + c<\/strong> within the terminal usually does the trick). <\/p>\n<style>.with-border{box-shadow: 0 0 20px #eee;}.syntaxhighlighter .plain{color: #333 !important;}.syntaxhighlighter .css.keyword{color: #006699 !important;}.syntaxhighlighter .css.value{color: #009900 !important;}.syntaxhighlighter .css.color3{color: red !important;}article.entry .syntaxhighlighter .line.highlighted.alt1,article.entry .syntaxhighlighter .line.highlighted.alt2 {background-color:rgba(55,118,254,0.1)!important;} article.entry .syntaxhighlighter .line.alt2{background-color: transparent !important;} article.entry .syntaxhighlighter .gutter .line.highlighted {border-right: 3px solid #3776fe !important; color:#3776fe !important;} .syntaxhighlighter .gutter .line {border-right: 3px solid #afafaf !important;} .syntaxhighlighter table caption{color: #bbb !important;}<\/style>\n","protected":false},"excerpt":{"rendered":"<p>Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required. Custom Fields for Divi Module Settings Creating a custom field for a Divi module is similar to creating a custom Divi module in the Divi Builder. Both methods require some Javascript, HTML, &#038; [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-3131","post","type-post","status-publish","format-standard","hentry","category-developers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Elegant Themes Documentation<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Create a Custom Field For a Divi Builder Module - Elegant Themes Documentation\" \/>\n<meta property=\"og:description\" content=\"Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required. Custom Fields for Divi Module Settings Creating a custom field for a Divi module is similar to creating a custom Divi module in the Divi Builder. Both methods require some Javascript, HTML, &#038; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/\" \/>\n<meta property=\"og:site_name\" content=\"Elegant Themes Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-10T00:27:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg\" \/>\n<meta name=\"author\" content=\"Jason Champagne\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason Champagne\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/\"},\"author\":{\"name\":\"Jason Champagne\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/#\\\/schema\\\/person\\\/39847d185839d0bffacf57ad26fafbe4\"},\"headline\":\"How To Create a Custom Field For a Divi Builder Module\",\"datePublished\":\"2021-01-10T00:27:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/\"},\"wordCount\":1955,\"image\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/update-divi-scripts-1.jpg\",\"articleSection\":[\"Developer Documentation\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/\",\"url\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/\",\"name\":\"How To Create a Custom Field For a Divi Builder Module - Elegant Themes Documentation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/update-divi-scripts-1.jpg\",\"datePublished\":\"2021-01-10T00:27:22+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/#\\\/schema\\\/person\\\/39847d185839d0bffacf57ad26fafbe4\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/update-divi-scripts-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/update-divi-scripts-1.jpg\",\"width\":880,\"height\":423},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/developers\\\/how-to-create-a-custom-field-for-a-divi-builder-module\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Create a Custom Field For a Divi Builder Module\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/#website\",\"url\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/\",\"name\":\"Elegant Themes Documentation\",\"description\":\"Just another WordPress site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.elegantthemes.com\\\/documentation\\\/#\\\/schema\\\/person\\\/39847d185839d0bffacf57ad26fafbe4\",\"name\":\"Jason Champagne\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55db84f9b8dc924d60214b8218d2684bbba7cd2af71ec9d0d5d0bf1c310b9169?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55db84f9b8dc924d60214b8218d2684bbba7cd2af71ec9d0d5d0bf1c310b9169?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55db84f9b8dc924d60214b8218d2684bbba7cd2af71ec9d0d5d0bf1c310b9169?s=96&d=mm&r=g\",\"caption\":\"Jason Champagne\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Elegant Themes Documentation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/","og_locale":"en_US","og_type":"article","og_title":"How To Create a Custom Field For a Divi Builder Module - Elegant Themes Documentation","og_description":"Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required. Custom Fields for Divi Module Settings Creating a custom field for a Divi module is similar to creating a custom Divi module in the Divi Builder. Both methods require some Javascript, HTML, &#038; [&hellip;]","og_url":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/","og_site_name":"Elegant Themes Documentation","article_published_time":"2021-01-10T00:27:22+00:00","og_image":[{"url":"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg","type":"","width":"","height":""}],"author":"Jason Champagne","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jason Champagne","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#article","isPartOf":{"@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/"},"author":{"name":"Jason Champagne","@id":"https:\/\/blocksylaunch.click\/documentation\/#\/schema\/person\/39847d185839d0bffacf57ad26fafbe4"},"headline":"How To Create a Custom Field For a Divi Builder Module","datePublished":"2021-01-10T00:27:22+00:00","mainEntityOfPage":{"@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/"},"wordCount":1955,"image":{"@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#primaryimage"},"thumbnailUrl":"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg","articleSection":["Developer Documentation"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/","url":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/","name":"How To Create a Custom Field For a Divi Builder Module - Elegant Themes Documentation","isPartOf":{"@id":"https:\/\/blocksylaunch.click\/documentation\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#primaryimage"},"image":{"@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#primaryimage"},"thumbnailUrl":"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg","datePublished":"2021-01-10T00:27:22+00:00","author":{"@id":"https:\/\/blocksylaunch.click\/documentation\/#\/schema\/person\/39847d185839d0bffacf57ad26fafbe4"},"breadcrumb":{"@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#primaryimage","url":"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg","contentUrl":"https:\/\/blocksylaunch.click\/documentation\/wp-content\/uploads\/2020\/11\/update-divi-scripts-1.jpg","width":880,"height":423},{"@type":"BreadcrumbList","@id":"https:\/\/blocksylaunch.click\/documentation\/developers\/how-to-create-a-custom-field-for-a-divi-builder-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blocksylaunch.click\/documentation\/"},{"@type":"ListItem","position":2,"name":"How To Create a Custom Field For a Divi Builder Module"}]},{"@type":"WebSite","@id":"https:\/\/blocksylaunch.click\/documentation\/#website","url":"https:\/\/blocksylaunch.click\/documentation\/","name":"Elegant Themes Documentation","description":"Just another WordPress site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blocksylaunch.click\/documentation\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blocksylaunch.click\/documentation\/#\/schema\/person\/39847d185839d0bffacf57ad26fafbe4","name":"Jason Champagne","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/55db84f9b8dc924d60214b8218d2684bbba7cd2af71ec9d0d5d0bf1c310b9169?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/55db84f9b8dc924d60214b8218d2684bbba7cd2af71ec9d0d5d0bf1c310b9169?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55db84f9b8dc924d60214b8218d2684bbba7cd2af71ec9d0d5d0bf1c310b9169?s=96&d=mm&r=g","caption":"Jason Champagne"}}]}},"_links":{"self":[{"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/posts\/3131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/comments?post=3131"}],"version-history":[{"count":57,"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/posts\/3131\/revisions"}],"predecessor-version":[{"id":3230,"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/posts\/3131\/revisions\/3230"}],"wp:attachment":[{"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/media?parent=3131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/categories?post=3131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blocksylaunch.click\/documentation\/wp-json\/wp\/v2\/tags?post=3131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}