This guide covers fields designed for making selections, from simple on/off toggles to complex, searchable multi-select dropdowns.
A key extra
for many of these fields is the 'options'
array. This is an associative array where the key
is the value that gets saved to the database, and the value
is the user-facing label.
'options' => [
'low' => 'Low Priority',
'medium' => 'Medium Priority',
'high' => 'High Priority',
]
checkbox
true
if checked, false
if unchecked.'description'
text is automatically wrapped in a <label>
tag with the checkbox, making the entire text clickable, which improves accessibility and user experience.$page->add_field(
'open_links_in_new_tab',
'general_section',
'checkbox',
'New Tab Behavior',
[
'description' => 'Enable this to open all external links in a new browser tab.',
'default' => true,
]
);
switch
true
if on, false
if off.'description'
is a clickable label.$page->add_field(
'enable_dark_mode',
'display_section',
'switch',
'Dark Mode',
[
'description' => 'Activate the dark mode theme for the front-end.',
'default' => false,
]
);
choice
extra
: 'options'
(array)$page->add_field(
'thumbnail_position',
'display_section',
'choice',
'Thumbnail Position',
[
'description' => 'Choose where to display the featured image on single posts.',
'default' => 'above_title',
'options' => [
'above_title' => 'Above the Post Title',
'below_title' => 'Below the Post Title',
'no_thumb' => 'Do Not Display',
],
]
);
buttons_group
choice
field.extra
: 'options'
(array)$page->add_field(
'content_alignment',
'display_section',
'buttons_group',
'Content Alignment',
[
'description' => 'Select the default text alignment for your content.',
'default' => 'left',
'options' => [
'left' => 'Left',
'center' => 'Center',
'right' => 'Right',
],
]
);
select
extra
: 'options'
(array)$page->add_field(
'font_selection',
'display_section',
'select',
'Primary Font',
[
'description' => 'Choose a font from the Google Fonts library.',
'default' => 'roboto',
'options' => [
'roboto' => 'Roboto',
'open_sans' => 'Open Sans',
'lato' => 'Lato',
'montserrat'=> 'Montserrat',
],
]
);
multi_check
['dashboard', 'media']
).extra
: 'options'
(array)$page->add_field(
'post_types_to_search',
'general_section',
'multi_check',
'Searchable Content',
[
'description' => 'Select which post types should be included in search results.',
'default' => ['post', 'page'],
'options' => [
'post' => 'Posts',
'page' => 'Pages',
'product' => 'Products',
'docs' => 'Documentation',
],
]
);
multi_select
extra
: 'options'
(array)$page->add_field(
'user_roles_access',
'advanced_section',
'multi_select',
'Roles with Access',
[
'description' => 'Select which user roles can access the premium features.',
'default' => ['administrator', 'editor'],
'options' => [
'administrator' => 'Administrator',
'editor' => 'Editor',
'author' => 'Author',
'contributor' => 'Contributor',
'subscriber' => 'Subscriber',
],
]
);
Now that you’ve mastered choice-based fields, the next section will cover fields for handling rich content, code, and media from the WordPress library.