add_settings_section() WordPress Function

The add_settings_section() function is used to add a new settings section to a settings page. The function takes three arguments: the ID of the settings section, the name of the settings section, and a callback function that will be used to display the settings section. The add_settings_section() function is used to add a new settings section to a settings page. The function takes three arguments: the ID of the settings section, the name of the settings section, and a callback function that will be used to display the settings section. The ID of the settings section is used to identify the section in the database. The name of the settings section is used to display the section title on the settings page. The callback function is used to display the settings form on the settings page.

add_settings_section( string $id, string $title, callable $callback, string $page ) #

Adds a new section to a settings page.


Description

Part of the Settings API. Use this to define new settings sections for an admin page. Show settings sections in your admin page callback function with do_settings_sections(). Add settings fields to your section with add_settings_field().

The $callback argument should be the name of a function that echoes out any content you want to show at the top of the settings section before the actual fields. It can output nothing if you want.


Top ↑

Parameters

$id

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

$title

(string)(Required)Formatted title of the section. Shown as the heading for the section.

$callback

(callable)(Required)Function that echos out any content at the top of the section (between heading and fields).

$page

(string)(Required)The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();


Top ↑

More Information

The callback function receives a single optional argument, which is an array with three elements. Example:

add_settings_section(
	'eg_setting_section',
	'Example settings section in reading',
	'eg_setting_section_callback_function',
	'reading'
);
function eg_setting_section_callback_function( $arg ) {
	// echo section intro text here
	echo '<p>id: ' . $arg['id'] . '</p>';             // id: eg_setting_section
	echo '<p>title: ' . $arg['title'] . '</p>';       // title: Example settings section in reading
	echo '<p>callback: ' . $arg['callback'] . '</p>'; // callback: eg_setting_section_callback_function
}

Top ↑

Source

File: wp-admin/includes/template.php

function add_settings_section( $id, $title, $callback, $page ) {
	global $wp_settings_sections;

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

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

	$wp_settings_sections[ $page ][ $id ] = array(
		'id'       => $id,
		'title'    => $title,
		'callback' => $callback,
	);
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.