Switch

The switch lets you add a field switch.

Switch

Parameters

Here are the parameters in adding switch.

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
boolean | optional

the default value of the field.

priority
integer | optional

determines the order of fields in section.

Example


Yano::field( 'switch', [
    'id'          => 'switchdb1',
    'label'       => 'Do you want to show?',
    'description' => 'Some description',
    'section'     => 'section_id',
    'priority'    => 1,
] );

Example with default value! note: default value must be provided boolean.


Yano::field( 'switch', [
    'id'          => 'switchdb1',
    'label'       => 'Do you want to show?',
    'description' => 'Some description',
    'section'     => 'section_id',
    'default'     => true,
    'priority'    => 1,
] );


Usage

The get_theme_mod() function is recommended to retrieve data.


// Returns boolean
$is_checked = get_theme_mod('switchdb1');