add_settings_section( string $id, string $title, callable $callback, string $page, array $args = array() )
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.
Parameters
- $id
-
(Required) Slug-name to identify the section. Used in the 'id' attribute of tags.
- $title
-
(Required) Formatted title of the section. Shown as the heading for the section.
- $callback
-
(Required) Function that echos out any content at the top of the section (between heading and fields).
- $page
-
(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
-
(Optional) Arguments used to create the settings section.<br>
- 'before_section'
(string) HTML content to prepend to the section's HTML output.<br> Receives the section's class name as%s
. <br> - 'after_section'
(string) HTML content to append to the section's HTML output. <br> - 'section_class'
(string) The class name to use for the section. <br>
Default value: array()
- 'before_section'
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__, 'WP-3.0.0',
/* translators: %s: misc */
sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
'misc'
)
);
$page = 'general';
}
if ( 'privacy' == $page ) {
_deprecated_argument( __FUNCTION__, 'WP-3.5.0',
/* translators: %s: privacy */
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);
}
Changelog
Version | Description |
---|---|
6.1.0 | Added an $args parameter for the section's HTML wrapper and class name. |
2.7.0 | Introduced. |