wp-settings-builder

4. Fields: Basic Inputs

These are the foundational fields for collecting simple text, numeric, and sensitive data. They cover the most common use cases for any settings page.

All fields are added to a section using the add_field() method. The common parameters are:

This guide focuses on the $type and the available $extras for each basic input field.


Common extras

The following keys can be used in the $extras array for most basic input fields:


Text

Example

$page->add_field(
    'company_name', 
    'general_section', 
    'text', 
    'Company Name',
    [
        'description' => 'Enter the name of your business.',
        'default'     => 'My Awesome Company',
        'html_attributes' => [
            'placeholder' => 'e.g., Stark Industries',
        ],
    ]
);

URL

Example

$page->add_field( 
    'privacy_policy_url', 
    'general_section', 
    'url', 
    'Privacy Policy URL', 
    [
        'description' => 'Link to your website\'s privacy policy.',
        'html_attributes' => [
            'placeholder' => 'https://example.com/privacy',
        ],
    ]
);

Email

Example

$page->add_field( 
    'support_email', 
    'general_section', 
    'email', 
    'Support Email', 
    [
        'description' => 'The email address where customers can reach you for support.',
        'default'     => get_option('admin_email'),
    ]
);

Number

Example

$page->add_field( 
    'items_per_page',
    'display_section',
    'number',
    'Items Per Page',
    [
        'description' => 'How many items to show on a single page.',
        'default'     => 10,
        'html_attributes' => [
            'min'  => 1,
            'max'  => 50,
            'step' => 1,
        ],
    ]
);

Password

Example

$page->add_field( 
    'api_secret_key', 
    'api_section', 
    'password', 
    'API Secret Key', 
    [
        'description' => 'Your secret key is stored securely and is never shown here.',
        'html_attributes' => [
            'autocomplete' => 'new-password', // Helps prevent browser auto-fill
        ],
    ]
);

Textarea

Example

$page->add_field( 
    'custom_css', 
    'advanced_section', 
    'textarea', 
    'Custom CSS', 
    [
        'description' => 'Add custom CSS rules here. They will be loaded on the front-end.',
        'html_attributes' => [
            'rows'        => 8,
            'cols'        => 50,
            'placeholder' => '.my-class { color: red; }',
        ],
    ]
);

Color

Example

$page->add_field(
    'primary_brand_color', 
    'display_section', 
    'color', 
    'Primary Brand Color', 
    [
        'description' => 'Select the primary color for your theme.',
        'default'     => '#3858e9',
    ]
);

With these basic fields, you can build the foundation of most settings pages. The next guide will explore fields designed for making choices, like toggles, radio buttons, and dropdowns.

Next: 5. Fields: Choice and Toggles