Fields
Types
Text

Text Field

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

Basic Usage

$stack->field('site_title', [
    'type' => 'text',
    'label' => 'Site Title',
    'default' => 'My Website',
    'description' => 'Enter your site title',
]);

Properties

PropertyTypeDefaultDescription
typestring-Required. Must be 'text'
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
placeholderstring''Placeholder text
maxlengthint-Maximum character length
minlengthint-Minimum character length
readonlyboolfalseMake field read-only
disabledboolfalseDisable the field
patternstring-Regex validation pattern

Examples

With Placeholder

$stack->field('company_name', [
    'type' => 'text',
    'label' => 'Company Name',
    'attributes' => [
        'placeholder' => 'Enter your company name',
    ],
]);

With Character Limit

$stack->field('meta_title', [
    'type' => 'text',
    'label' => 'Meta Title',
    'description' => 'Maximum 60 characters for SEO',
    'attributes' => [
        'maxlength' => 60,
    ],
]);

Read-only Field

$stack->field('license_key', [
    'type' => 'text',
    'label' => 'License Key',
    'default' => 'XXXX-XXXX-XXXX-XXXX',
    'attributes' => [
        'readonly' => true,
    ],
]);

With Conditional Display

$stack->field('custom_title', [
    'type' => 'text',
    'label' => 'Custom Title',
    'conditions' => [
        ['field' => 'use_custom_title', 'operator' => '==', 'value' => true],
    ],
]);

Retrieving Value

// For options
$title = my_option('site_title', 'Default Title');
 
// For post meta
$title = get_post_meta($post_id, 'site_title', true);

Output Example

<h1><?php echo esc_html(my_option('site_title', 'My Website')); ?></h1>

Related Fields