Skip to content

Textarea Field

A multi-line text input field.

A multi-line text input for longer plain-text values.

Overview

The Textarea field renders a resizable multi-line text input and returns a plain string including any line breaks the user enters. Use it for longer content such as descriptions, custom messages, footer text, copyright notices, about blurbs, or any other setting that may span multiple lines.

For single-line text use the Text field. For content that should preserve HTML markup use the Raw field.

Field Registration

📄<code>php
[
    'id'          => 'footer_text',
    'type'        => 'textarea',
    'title'       => __( 'Footer Text', 'your-textdomain' ),
    'subtitle'    => __( 'Shown in the footer area of every page', 'your-textdomain' ),
    'default'     => __( '© 2026 My Theme. All rights reserved.', 'your-textdomain' ),
    'placeholder' => __( 'Enter footer text…', 'your-textdomain' ),
    'rows'        => 4,
]

Field Options

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

subtitle and desc serve the same purpose and render in the same position below the label. If both are provided, subtitle takes priority.

Return Value

Type: string

Returns the text entered by the user, preserving any line breaks, 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
$footer_text = themeplus_get_option( 'footer_text', '' );
// Returns: '© 2026 My Theme. All rights reserved.'

Usage Examples

Basic plain text output

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

if ( $footer_text ) {
    echo '<p class="footer-text">' . esc_html( $footer_text ) . '</p>';
}

Preserving line breaks as paragraph tags

📄<code>php
$description = themeplus_get_option( 'about_description', '' );

if ( $description ) {
    echo '<div class="about-text">';
    echo wp_kses_post( wpautop( esc_html( $description ) ) );
    echo '</div>';
}

Preserving line breaks as <br> tags

📄<code>php
$message = themeplus_get_option( 'contact_message', '' );

if ( $message ) {
    echo '<p class="contact-message">' . nl2br( esc_html( $message ) ) . '</p>';
}

Custom copyright notice with dynamic year

📄<code>php
$copyright = themeplus_get_option( 'copyright_text', '' );

if ( $copyright ) {
    // Replace {year} placeholder with the current year
    $copyright = str_replace( '{year}', gmdate( 'Y' ), $copyright );
    echo '<div class="copyright">' . esc_html( $copyright ) . '</div>';
}

With a conditional field

📄<code>php
[
    'id'      => 'show_custom_404',
    'type'    => 'toggle',
    'title'   => __( 'Custom 404 Message', 'your-textdomain' ),
    'default' => false,
],
[
    'id'          => 'custom_404_text',
    'type'        => 'textarea',
    'title'       => __( '404 Message Text', 'your-textdomain' ),
    'placeholder' => __( 'Sorry, the page you are looking for could not be found.', 'your-textdomain' ),
    'rows'        => 4,
    'required'    => ['show_custom_404', '==', true],
],

Notes

  • The value is sanitized with sanitize_textarea_field()before storage — HTML tags are stripped and line breaks are preserved. Do not use this field to store HTML markup.
  • Always escape output with esc_html() for plain text output. Use nl2br( esc_html( $value ) ) to convert line breaks to <br> tags, or wpautop( esc_html( $value ) ) to convert them to <p> tags.
  • For single-line text, use the Text field. For content that should store and output HTML, use the Raw field.

On This Page