Checkbox

The checkbox lets you add a field checkbox.

Checkbox

Parameters

Here are the parameters in adding checkbox.

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.

Note: default value must be provided boolean.

priority
integer | optional

determines the order of fields in section.

Example


Yano::field( 'checkbox', [
    'id'          => 'checkboxdb1',
    'label'       => 'Are you single?',
    'description' => 'Select if your single',
    'section'     => 'section_id',
    'priority'    => 1,
] );

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


Yano::field( 'checkbox', [
    'id'          => 'checkboxdb1',
    'label'       => 'Are you single?',
    'description' => 'Select if your single',
    'section'     => 'section_id',
    'default'     => true,
    'priority'    => 1,
] );

Usage

The get_theme_mod() function is recommended to retrieve data.


// Return a boolean
$is_checked = get_theme_mod('checkboxdb1');