Code Editor

The code-editor lets you add a code editor field.

Code Editor

Parameters

Here are the parameters in adding code-editor.

id
string | required

a unique slug-like string to use as an id and also as index in saving data in database.

label
string | optional

the label of the field.

description
string | optional

the description of the field and display under the label.

section
string | requiredl

the section where the field will be displayed.

default
string | optional

the default value of the field.

priority
integer | optional

determines the order of fields in section.

language
string | optional | default: html

allowing to set programming language for the editor

Note: here are the list of allowed language [ 'html', 'css', 'javascript', 'php' ]

Example


Yano::field( 'code-editor', [
   'id'          => 'codedb1',
   'label'       => 'Add Your Code',
   'description' => 'Description Here.',
   'section'     => 'section_id',
   'priority'    => 1
] );

Example with default value! note: default value must exist in choices.


Yano::field( 'code-editor', [
   'id'          => 'codedb1',
   'label'       => 'Add Your Code',
   'description' => 'Description Here.',
   'section'     => 'section_id',
   'default'     => 'Hello World'
   'priority'    => 1
] );

Example with langauage! note: here are the list of allowed language html, css, javascript and php.


Yano::field( 'code-editor', [
   'id'          => 'codedb1',
   'label'       => 'Add Your Code',
   'description' => 'Description Here.',
   'section'     => 'section_id',
   'default'     => 'console.log('Hello World')'
   'priority'    => 1,
   'language'    => 'javascript'
] );

Usage

The get_theme_mod() function is recommended to retrieve data.


// Return a string
echo get_theme_mod('codedb1');