Settings Sections are the groups of settings you see on WordPress settings pages with a shared heading. In your plugin you can add new sections to existing settings pages rather than creating a whole new page. This makes your plugin simpler to maintain and creates less new pages for users to learn. You just tell them to change your setting on the relevant existing page.

add_settings_section() 描述


<?php add_settings_section$id$title$callback$page ); ?>

add_settings_section() 用法



(string) (必填) String for use in the 'id' attribute of tags.

默认值: None


(string) (必填) Title of the section.

默认值: None


(string) (必填) Function that fills the section with the desired content. The function should echo its output.

默认值: None


(string) (必填) The menu page on which to display this section. Should match $menu_slug from Function Reference/add theme page

默认值: None

add_settings_section() 参数



This function does not return a value.

add_settings_section() 返回值


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

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */

	'Example settings section in 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

add_settings_section() 注意


添加于 版本: 2.7.0

add_settings_section() 历史


add_settings_section() 函数的代码位于 wp-admin/includes/template.php.

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */
 * Add a new section to a settings page.
 * 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.
 * @since 2.7.0
 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
 * @param string $id       Slug-name to identify the section. Used in the 'id' attribute of tags.
 * @param string $title    Formatted title of the section. Shown as the heading for the section.
 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
 * @param string $page     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();
function add_settings_section($id, $title, $callback, $page) {
	global $wp_settings_sections;

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

	if ( 'privacy' == $page ) {
		_deprecated_argument( __FUNCTION__, '3.5', sprintf( __( '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);

add_settings_section() 源文件