1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Fields
  5. Code Editor Field

Code Editor Field

Arguments

NameTypeDefaultDescription
idstring A unique ID. This ID will be used to get the value
typestringcode_editorType of the field
titlestring Title of the field
defaultstring Default value from database, if the option doesn’t exist
subtitlestring Subtitle to display below the title
descstring Description to display after the field
helpstring Text to display on right-corder (as hover/popup) of the field
classstring Extra CSS classes (space separated) to append to the field
beforestring Content to display before the field
afterstring Content to display after the field
dependencyarray Define field visibility to append to the field
attributesarray Extra HTML attributes to append to the field
sanitizestring Callback function for sanitizing value
validatestring Callback function for validating value
EXTRAS   
settingsarray An associative array containing arguments for the setting

settings Arguments

NameTypeDefaultDescription
modestringhtmlmixedSets the language mode of the editor (css, javascript, php, htmlmixed)
themestringdefaultSets the theme of the editor (mbo, monokai, ambiance)
lineNumbersbooltrueFlag to display line numbers to the left of the editor
tabSizenumber2The width of a tab space

Get more information from the codemirror arguments

Simple Code Editor Example

array(
  'id' => 'example-code-editor',
  'type' => 'code_editor',
  'title' => 'Code Editor',
),

HTML Code Editor Example

array(
  'id' => 'example-html-editor',
  'type' => 'code_editor',
  'title' => 'HTML Editor',
  'settings' => array(
    'theme' => 'mdn-like',
    'mode' => 'htmlmixed',
  ),
  'default' => '<h1>Hello World</h1>',
),

CSS Code Editor Example

array(
  'id' => 'example-css-editor',
  'type' => 'code_editor',
  'title' => 'CSS Editor',
  'settings' => array(
    'theme' => 'mbo',
    'mode' => 'css',
  ),
  'default' => '.element{ color: #ffbc00; }',
),

Javascript Code Editor Example

array(
  'id' => 'example-js-editor',
  'type' => 'code_editor',
  'title' => 'Javascript Editor',
  'settings' => array(
    'theme' => 'monokai',
    'mode' => 'javascript',
  ),
  'default' => 'console.log("Hello World");',
),
Was this article helpful to you? Yes No

How can we help?