函数原型
add_settings_section( string $id, string $title, callable $callback, string $page, array $args = array() )
函数描述
Adds a new section to a settings page.
是否弃用
未弃用
函数参数
-
$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() ; -
$args
array
Optional - Arguments used to create the settings section.
before_sectionstringHTML content to prepend to the section’s HTML output.
Receives the section’s class name as%s.after_sectionstringHTML content to append to the section’s HTML output.section_classstringThe class name to use for the section.
Default:
array()
函数返回值
无
函数位置
File: wp-admin/includes/template.php.
函数源码
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
}源码链接
变更日志
| Version | Description |
|---|---|
| 6.1.0 | Added an $args parameter for the section’s HTML wrapper and class name. |
| 2.7.0 | Introduced. |

