Function: add_settings_field

add_settings_field( string $id, string $title, callable $callback, string $page, string $section, array $args )

Add a new field to a section of a settings page.

Shortcut: asf

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

Part of the Settings API. Use this to define a settings field that will show as part of a settings section inside a settings page. The fields are shown using do_settings_fields() in do_settings-sections()

The $callback argument should be the name of a function that echoes out the html input tags for this setting field. Use get_option() to retrieve existing values to show.

Parameters

Name Type(s) Default Value Description
$id string

Slug-name to identify the field. Used in the 'id' attribute of tags.

$title string

Formatted title of the field. Shown as the label for the field during output.

$callback callable

Function that fills the field with the desired form inputs. The function should echo its output.

$page string

The slug-name of the settings page on which to show the section (general, reading, writing, ...).

$section string 'default'

Optional. The slug-name of the section of the settings page in which to show the box. Default 'default'.

$args array array()

{ Optional. Extra arguments used when outputting the field.

@type string $label_for When supplied, the setting title will be wrapped
                        in a `<label>` element, its `for` attribute populated
                        with this value.
@type string $class     CSS Class to be added to the `<tr>` element when the
                        field is output.

}

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.