bookmark_borderradio Field

Introduction

The radio type field, part of the Settings API, renders a radio type input for each of the field choices.

Example

The radio button has a default_value of “this is the label for choice2” so the second choice will be selected. Because horizontal is set to true, the radio buttons will be displayed side-by-side instead of the default one per line.

array(
	'title'       => esc_html__( 'This is the title for Section 2', 'sometextdomain' ),
	'description' => esc_html__( 'This is a description of the purpose of Section 2', 'sometextdomain' ),
	'fields'      => array(
		array(
			'type'          => 'radio',
			'name'          => 'myradio',
			'label'         => esc_html__( 'this is the main label for the radio buttons', 'sometextdomain' ),
			'default_value' => 'this is the label for choice2',
			'horizontal'    => true,
			'choices'       => array(
				array(
					'name'    => 'choice1',
					'tooltip' => esc_html__( 'this is the tooltip for choice1', 'sometextdomain' ),
					'label'   => esc_html__( 'this is the label for choice1', 'sometextdomain' ),
					'value'   => 'this is the value for choice1'
				),
				array(
					'name'    => 'choice2',
					'tooltip' => esc_html__( 'this is the tooltip for choice2', 'sometextdomain' ),
					'label'   => esc_html__( 'this is the label for choice2', 'sometextdomain' ),
				),
			),
		),
	),
),

The code above will render the radio button field similar to the following:
Radio Field Example

Uses