View Categories

Field Type: Switch

Table of Contents

A toggle switch for Boolean on/off values, perfect for enabling or disabling features.

Example Usage #

sample-plugin.php
array(
	'id'      => 'app_status',
	'title'   => 'Enable Application',
	'label'   => 'Turn on to activate the application features',
	'type'    => 'switch',
	'default' => 'yes',
	'value'   => get_option( 'app_status' ),
),

Properties #

  • id (required) – Unique identifier for the field
  • title (required) – Label displayed for the switch
  • label (optional) – Additional descriptive text shown next to the switch
  • type (required) – Must be 'switch'
  • default (optional) – Default state: 'yes' or 'no'
  • value (optional) – Current saved value: 'yes' or 'no'

Notes #

The switch returns 'yes' when enabled and 'no' when disabled. Always use these string values, not boolean true/false.