Fields
Types
Textarea

Textarea Field

A multi-line text input field for longer text content.

Basic Usage

$stack->field('description', [
    'type' => 'textarea',
    'label' => 'Description',
    'default' => '',
    'description' => 'Enter a detailed description',
]);

Properties

PropertyTypeDefaultDescription
typestring-Required. Must be 'textarea'
labelstring-Field label displayed to users
descriptionstring''Help text below the field
defaultstring''Default value
attributesarray[]Additional HTML attributes
conditionsarray[]Conditional display rules

Attributes

AttributeTypeDefaultDescription
rowsint5Number of visible text rows
colsint-Number of visible text columns
placeholderstring''Placeholder text
maxlengthint-Maximum character length
readonlyboolfalseMake field read-only
disabledboolfalseDisable the field

Examples

Basic Textarea

$stack->field('bio', [
    'type' => 'textarea',
    'label' => 'Biography',
    'description' => 'Write a short biography',
    'attributes' => [
        'rows' => 4,
        'placeholder' => 'Tell us about yourself...',
    ],
]);

With Character Limit

$stack->field('meta_description', [
    'type' => 'textarea',
    'label' => 'Meta Description',
    'description' => 'Maximum 160 characters for SEO',
    'attributes' => [
        'rows' => 2,
        'maxlength' => 160,
    ],
]);

Large Text Area

$stack->field('terms_content', [
    'type' => 'textarea',
    'label' => 'Terms & Conditions',
    'attributes' => [
        'rows' => 15,
    ],
]);

Copyright Text with Tokens

$stack->field('copyright_text', [
    'type' => 'textarea',
    'label' => 'Copyright Text',
    'default' => '© {year} {site_name}. All rights reserved.',
    'description' => 'Use {year} for current year, {site_name} for site name',
    'attributes' => [
        'rows' => 2,
    ],
]);

Retrieving Value

// For options
$description = my_option('description', '');
 
// Process tokens
$copyright = my_option('copyright_text', '');
$copyright = str_replace(
    ['{year}', '{site_name}'],
    [date('Y'), get_bloginfo('name')],
    $copyright
);

Output Example

<div class="description">
    <?php echo nl2br(esc_html(my_option('description', ''))); ?>
</div>
 
// Or with HTML allowed
<div class="content">
    <?php echo wp_kses_post(my_option('content', '')); ?>
</div>

Related Fields

  • text - For single-line text
  • wysiwyg - For rich text with formatting
  • code - For code snippets