On this page
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
$idstring Required-
Slug-name to identify the section. Used in the
'id'attribute of tags. $titlestring Required-
Formatted title of the section. Shown as the heading for the section.
$callbackcallable Required-
Function that echos out any content at the top of the section (between heading and fields).
$pagestring 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() ; $argsarray 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()
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
}
Source
File: wp-admin/includes/template.php. View all references
function add_settings_section( $id, $title, $callback, $page, $args = array() ) {
global $wp_settings_sections;
$defaults = array(
'id' => $id,
'title' => $title,
'callback' => $callback,
'before_section' => '',
'after_section' => '',
'section_class' => '',
);
$section = wp_parse_args( $args, $defaults );
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 ] = $section;
}
Related
Uses
| Uses | Description |
|---|---|
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _deprecated_argument() wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/add_settings_section