Summery Summery

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

Syntax Syntax

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

Description Description

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 Parameters


(string) (Required) Slug-name to identify the field. Used in the 'id' attribute of tags.


(string) (Required) Formatted title of the field. Shown as the label for the field during output.


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


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


(string) (Optional) The slug-name of the section of the settings page in which to show the box.

Default value: 'default'


(array) (Optional) Extra arguments used when outputting the field.

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

Default value: array()

Source Source

File: wp-admin/includes/template.php

function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
	global $wp_settings_fields;

	if ( 'misc' === $page ) {
				/* translators: %s: misc */
				__( 'The "%s" options group has been removed. Use another settings group.' ),
		$page = 'general';

	if ( 'privacy' === $page ) {
				/* translators: %s: privacy */
				__( 'The "%s" options group has been removed. Use another settings group.' ),
		$page = 'reading';

	$wp_settings_fields[ $page ][ $section ][ $id ] = array(
		'id'       => $id,
		'title'    => $title,
		'callback' => $callback,
		'args'     => $args,


Changelog Changelog

Version Description
4.2.0 The $class argument was added.
2.7.0 Introduced.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.