wp-settings-builder

6. Fields: Content and Media

This guide covers fields designed for handling rich content, custom code, and assets from the WordPress Media Library. These fields provide powerful, integrated experiences for content management directly within your settings page.


WYSIWYG Editor

Key extra: editor_settings

You can customize nearly every aspect of the editor by passing an array to the 'editor_settings' key. This array is passed directly to the WordPress wp_editor() function.

Common editor_settings options:

For a complete list of options, see the official WordPress Developer documentation for wp_editor().

Example

$page->add_field( 
    'site_footer_bio',
    'content_section', 
    'wysiwyg', 
    'Footer Biography', 
        [
        'description' => 'This content will appear in the site footer.',
        'default'     => '<h2>About Us</h2><p>We are an awesome company.</p>',
        'editor_settings' => [
            'textarea_rows' => 8,
            'media_buttons' => false, // Don't allow images in the bio
            'teeny'         => true,  // Use the minimal "teeny" editor
        ],
    ]
);

Code Editor

Key extras

Example

$page->add_field(
    'header_scripts', 
    'advanced_section', 
    'code_editor', 
    'Header Scripts', 
    [
        'description' => 'Add scripts to the <head> of your site. Use with caution.',
        'mode'        => 'text/html',
        'html_attributes' => [
            'rows' => 10,
        ],
        'editor_settings' => [
            'lineNumbers' => true,
            'indentUnit'  => 4,
        ],
    ]
);

Media (Single)

Key extra: media_settings

Use the 'media_settings' array to customize the Media Library modal window.

Example

$page->add_field( 
    'site_logo', 
    'branding_section', 
    'media', 
    'Site Logo', 
    [
        'description' => 'Upload or select the primary logo for the website.',
        'media_settings' => [
            'title'        => 'Choose a Logo',
            'button_text'  => 'Use this Logo',
            'library_type' => 'image', // Only allow images to be selected
        ],
    ]
);

Media (Multiple)

Key extra: media_settings

The 'media_settings' options work the same as for the single media field but are best phrased for a multi-selection context.

Example

$page->add_field( 'homepage_gallery', 'content_section', 'media_multiple', 'Homepage Gallery Images', [
    'description' => 'Select multiple images to display in the homepage gallery.',
    'media_settings' => [
        'title'       => 'Build Your Gallery',
        'button_text' => 'Add to Gallery',
    ],
]);

These fields provide a robust way to manage complex content. The next guide will explore the various date and time picker fields available in the framework.

Next: 7. Fields: Date and Time