Overview
The Text field is the most basic input type in ThemePlus. It renders a single-line text input and returns a plain string value. Use it for short content like headings, labels, URLs, email addresses, or any other single-line text.
Field Registration
php
[
'id' => 'site_tagline',
'type' => 'text',
'title' => __('Site Tagline', 'your-textdomain'),
'subtitle' => __('Shown below the logo', 'your-textdomain'),
'default' => 'Welcome to my site',
]
Field Options
| Option | Type | Required | Description |
|---|---|---|---|
id | string | ✅ | Unique field identifier — used as the option key |
type | string | ✅ | Must be text |
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 value |
placeholder | string | — | Placeholder text shown inside the input when empty |
required | array | — | Conditional logic rules — see Conditional Logic |
Return Value
Type: string
Returns the text entered by the user, or the default value if nothing has been saved yet.
php
$tagline = themeplus_get_option( 'site_tagline', 'Welcome to my site' );
// Returns: 'Welcome to my site'
Usage Examples
Basic output
php
$tagline = themeplus_get_option( 'site_tagline', '' );
if ( $tagline ) {
echo '<p class="site-tagline">' . esc_html( $tagline ) . '</p>';
}
As a page title
php
$custom_title = themeplus_get_option( 'custom_page_title', get_the_title() );
echo '<h1>' . esc_html( $custom_title ) . '</h1>';
In an HTML attribute
php
$phone = themeplus_get_option( 'contact_phone', '' );
if ( $phone ) {
echo '<a href="tel:' . esc_attr( $phone ) . '">' . esc_html( $phone ) . '</a>';
}
With a conditional field
php
[
'id' => 'enable_announcement',
'type' => 'toggle',
'title' => __('Enable Announcement Bar', 'your-textdomain'),
'default' => false,
],
[
'id' => 'announcement_text',
'type' => 'text',
'title' => __('Announcement Text', 'your-textdomain'),
'default' => 'Free shipping on all orders!',
'required' => ['enable_announcement', '==', true],
],
Notes
- Always escape output with
esc_html()when displaying in HTML content, oresc_attr()when used inside an HTML attribute. - For multi-line text, use the Textarea field instead.
- For rich text with HTML formatting, use the Raw field.