Radio

The radio lets you add a field radio.

Radio

Parameters

Here are the parameters in adding radio.

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 | required

the section where the field will be displayed.

default
string | optional

the default value of the field.

Note: default value must exist within the choices.

priority
integer | optional

determines the order of fields in section.

choices
array | required

list of choices.

Example


Yano::field( 'radio', [
   'id'             => 'radiodb1',
   'label'          => 'Choose your country',
   'description'    => 'Select your country.',
   'section'        => 'section_id',
   'priority'       => 1,
   'choices'        => [
      'america'     => __( 'America' ),
      'philippines' => __( 'Philippines' ),
      'peru'        => __( 'Peru' )
   ]
] );

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


Yano::field( 'radio', [
   'id'             => 'radiodb1',
   'label'          => 'Choose your country',
   'description'    => 'Select your country.',
   'section'        => 'section_id',
   'default'        => 'philippines',
   'priority'       => 1,
   'choices'        => [
      'america'     => __( 'America' ),
      'philippines' => __( 'Philippines' ),
      'peru'        => __( 'Peru' )
   ]
] );

Usage

The get_theme_mod() function is recommended to retrieve data.


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