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.
1715functionadd_settings_field($id,$title,$callback,$page,$section='default',$args=array()){1716global$wp_settings_fields;17171718if('misc'===$page){1719_deprecated_argument(1720__FUNCTION__,1721'3.0.0',1722sprintf(1723/* translators: %s: misc */1724__('The "%s" options group has been removed. Use another settings group.'),1725'misc'1726)1727);1728$page='general';1729}17301731if('privacy'===$page){1732_deprecated_argument(1733__FUNCTION__,1734'3.5.0',1735sprintf(1736/* translators: %s: privacy */1737__('The "%s" options group has been removed. Use another settings group.'),1738'privacy'1739)1740);1741$page='reading';1742}17431744$wp_settings_fields[$page][$section][$id]=array(1745'id'=>$id,1746'title'=>$title,1747'callback'=>$callback,1748'args'=>$args,1749);1750}
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 7.0.4 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.