Skip to content

Text Field

A single-line text input field.

A single-line text input for short plain-text values.

Overview

The Text field renders a single-line text input and returns a plain string. Use it for short content like headings, taglines, labels, phone numbers, email addresses, custom URLs, or any other single-line text setting in your theme.

For multi-line text use the Textarea field. For rich text with HTML use the Raw field.

Field Registration

📄<code>php
[
    'id'          => 'site_tagline',
    'type'        => 'text',
    'title'       => __( 'Site Tagline', 'your-textdomain' ),
    'subtitle'    => __( 'Shown below the logo in the header', 'your-textdomain' ),
    'default'     => __( 'Welcome to my site', 'your-textdomain' ),
    'placeholder' => __( 'Enter a tagline…', 'your-textdomain' ),
]

Field Options

OptionTypeRequiredDescription
idstring✅Unique field identifier — used as the option key
typestring✅Must be text
titlestring✅Label shown above the field
subtitlestring—Smaller descriptive text shown below the label
descstring—Alternative to subtitle â€” shown in the same position below the label
placeholderstring—Placeholder text shown inside the input when empty
defaultstring—Default value returned when nothing has been saved yet
requiredarray—Conditional logic rules — see Conditional Logic

subtitle and desc serve the same purpose — use whichever reads more naturally in your config. If both are provided, subtitle takes priority.

Return Value

Type: string

Returns the value entered by the user, or the default value if nothing has been saved yet. Returns an empty string '' if no default is set and nothing has been saved.

📄<code>php
$tagline = themeplus_get_option( 'site_tagline', 'Welcome to my site' );
// Returns: 'Welcome to my site'

Usage Examples

Basic output

📄<code>php
$tagline = themeplus_get_option( 'site_tagline', '' );

if ( $tagline ) {
    echo '<p class="site-tagline">' . esc_html( $tagline ) . '</p>';
}

As a page heading

📄<code>php
$custom_title = themeplus_get_option( 'custom_page_title', get_the_title() );

echo '<h1 class="page-title">' . esc_html( $custom_title ) . '</h1>';

In an HTML attribute

📄<code>php
$phone = themeplus_get_option( 'contact_phone', '' );

if ( $phone ) {
    echo '<a href="tel:' . esc_attr( $phone ) . '" class="phone-link">' . esc_html( $phone ) . '</a>';
}

As a CSS custom property

📄<code>php
$custom_font = themeplus_get_option( 'custom_font_name', '' );

if ( $custom_font ) {
    echo '<style>:root { --custom-font: "' . esc_attr( $custom_font ) . '", sans-serif; }</style>';
}

With a conditional field

📄<code>php
[
    'id'      => 'enable_announcement',
    'type'    => 'toggle',
    'title'   => __( 'Enable Announcement Bar', 'your-textdomain' ),
    'default' => false,
],
[
    'id'          => 'announcement_text',
    'type'        => 'text',
    'title'       => __( 'Announcement Text', 'your-textdomain' ),
    'placeholder' => __( 'Free shipping on all orders!', 'your-textdomain' ),
    'default'     => __( 'Free shipping on all orders!', 'your-textdomain' ),
    'required'    => ['enable_announcement', '==', true],
],

Notes

  • Always escape output with esc_html() when displaying in HTML content, or esc_attr() when used inside an HTML attribute value.
  • The value is sanitized with sanitize_text_field() before storage — HTML tags are stripped. Do not use this field to store HTML markup.
  • For multi-line text, use the Textarea field. For content that should preserve HTML, use the Raw field.

On This Page