Overview
The Select field renders a searchable dropdown input and returns the selected option value as a string. Use it for layout choices, style presets, position settings, post selections, or any option where the user needs to pick one item from a defined list.
Field Registration
php
[
'id' => 'header_layout',
'type' => 'select',
'title' => __('Header Layout', 'your-textdomain'),
'subtitle' => __('Choose the header style', 'your-textdomain'),
'default' => 'standard',
'options' => [
'standard' => __('Standard', 'your-textdomain'),
'centered' => __('Centered', 'your-textdomain'),
'fullwidth' => __('Full Width', 'your-textdomain'),
'minimal' => __('Minimal', 'your-textdomain'),
],
]
Field Options
| Option | Type | Required | Description |
|---|---|---|---|
id | string | ✅ | Unique field identifier — used as the option key |
type | string | ✅ | Must be select |
title | string | ✅ | Label shown above the field |
subtitle | string | — | Smaller descriptive text shown below the label |
desc | string | — | Help text shown below the input |
default | string | — | Default selected value — must match a key in options |
options | array | ✅ | Key-value pairs — key is stored, value is the label shown |
required | array | — | Conditional logic rules — see Conditional Logic |
Return Value
Type: string
Returns the key of the selected option, or the default value if nothing has been saved yet.
php
$layout = themeplus_get_option( 'header_layout', 'standard' );
// Returns: 'standard'
Usage Examples
Applying a CSS class
php
$header_layout = themeplus_get_option( 'header_layout', 'standard' );
echo '<header class="site-header site-header--' . esc_attr( $header_layout ) . '">';
Mapping value to a label
php
$layout = themeplus_get_option( 'header_layout', 'standard' );
$labels = [
'standard' => 'Standard',
'centered' => 'Centered',
'fullwidth' => 'Full Width',
'minimal' => 'Minimal',
];
echo esc_html( $labels[ $layout ] ?? $layout );
Conditional template logic
php
$blog_style = themeplus_get_option( 'blog_style', 'grid' );
if ( $blog_style === 'grid' ) {
get_template_part( 'template-parts/blog/grid' );
} elseif ( $blog_style === 'list' ) {
get_template_part( 'template-parts/blog/list' );
} else {
get_template_part( 'template-parts/blog/masonry' );
}
Dynamically populated options
php
// Populate with registered post types
$post_types = get_post_types( ['public' => true], 'objects' );
$options = [];
foreach ( $post_types as $post_type ) {
$options[ $post_type->name ] = $post_type->label;
}
themeplus_add_section([
'id' => 'blog',
'title' => __('Blog', 'your-textdomain'),
'icon' => 'fa-solid fa-newspaper',
'fields' => [
[
'id' => 'portfolio_post_type',
'type' => 'select',
'title' => __('Portfolio Post Type', 'your-textdomain'),
'options' => $options,
'default' => 'post',
],
],
]);
With a conditional field
php
[
'id' => 'footer_layout',
'type' => 'select',
'title' => __('Footer Layout', 'your-textdomain'),
'default' => '3-col',
'options' => [
'1-col' => __('1 Column', 'your-textdomain'),
'2-col' => __('2 Columns', 'your-textdomain'),
'3-col' => __('3 Columns', 'your-textdomain'),
'4-col' => __('4 Columns', 'your-textdomain'),
],
],
[
'id' => 'footer_widget_title',
'type' => 'text',
'title' => __('Widget Area Title', 'your-textdomain'),
'required' => ['footer_layout', '!=', '1-col'],
],
Notes
- The
optionsarray keys are what get stored in the database and returned bythemeplus_get_option()— keep them lowercase, hyphenated, and stable across theme versions. - Always sanitize the returned value before using it in class names or template logic — use
esc_attr()for HTML attributes andsanitize_key()for internal comparisons. - For a visual button-based alternative to a dropdown, use the Button Set field.
- For choosing between options with images, use the Select Image field.
- For allowing multiple selections, use the Checkbox field.