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
$idstring
Slug-name to identify the field. Used in the 'id' attribute of tags.
$titlestring
Formatted title of the field. Shown as the label for the field during output.
$callbackcallable
Function that fills the field with the desired form inputs. The function should echo its output.
$pagestring
The slug-name of the settings page on which to show the section (general, reading, writing, ...).
$sectionstringoptional
The slug-name of the section of the settings page in which to show the box. Default 'default'.Default: 'default'
$argsarrayoptional
Extra arguments that get passed to the callback function.Default: array()
$label_forstring
When supplied, the setting title will be wrapped in a <label> element, its for attribute populated with this value.
$classstring
CSS Class to be added to the <tr> element when the field is output.
Uses · 2
_deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
1710functionadd_settings_field($id,$title,$callback,$page,$section='default',$args=array()){1711global$wp_settings_fields;17121713if('misc'===$page){1714_deprecated_argument(1715__FUNCTION__,1716'3.0.0',1717sprintf(1718/* translators: %s: misc */1719__('The "%s" options group has been removed. Use another settings group.'),1720'misc'1721)1722);1723$page='general';1724}17251726if('privacy'===$page){1727_deprecated_argument(1728__FUNCTION__,1729'3.5.0',1730sprintf(1731/* translators: %s: privacy */1732__('The "%s" options group has been removed. Use another settings group.'),1733'privacy'1734)1735);1736$page='reading';1737}17381739$wp_settings_fields[$page][$section][$id]=array(1740'id'=>$id,1741'title'=>$title,1742'callback'=>$callback,1743'args'=>$args,1744);1745}
History
Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
4.2.0
The $class argument was added.from the docblock
2.7.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-admin/includes/template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.