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.
1713functionadd_settings_field($id,$title,$callback,$page,$section='default',$args=array()){1714global$wp_settings_fields;17151716if('misc'===$page){1717_deprecated_argument(1718__FUNCTION__,1719'3.0.0',1720sprintf(1721/* translators: %s: misc */1722__('The "%s" options group has been removed. Use another settings group.'),1723'misc'1724)1725);1726$page='general';1727}17281729if('privacy'===$page){1730_deprecated_argument(1731__FUNCTION__,1732'3.5.0',1733sprintf(1734/* translators: %s: privacy */1735__('The "%s" options group has been removed. Use another settings group.'),1736'privacy'1737)1738);1739$page='reading';1740}17411742$wp_settings_fields[$page][$section][$id]=array(1743'id'=>$id,1744'title'=>$title,1745'callback'=>$callback,1746'args'=>$args,1747);1748}
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.8.8 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.