add_settings_section

Add a new section to a settings page.

Description

add_settings_section( (string) $id, (string) $title, (callable) $callback, (string) $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.

Parameters (4)

0. $id (string)
Slug-name to identify the section. Used in the id attribute of tags.
1. $title (string)
Formatted title of the section. Shown as the heading for the section.
2. $callback (callable)
Function that echos out any content at the top of the section (between heading and fields).
3. $page (string)
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();

Usage

  1. if ( !function_exists( 'add_settings_section' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Slug-name to identify the section. Used in the 'id' attribute of tags. 
  5. $id = ''; 
  6.  
  7. // Formatted title of the section. Shown as the heading for the section. 
  8. $title = ''; 
  9.  
  10. // Function that echos out any content at the top of the section (between heading and fields). 
  11. $callback = null; 
  12. $page = ''; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = add_settings_section($id, $title, $callback, $page); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function add_settings_section($id, $title, $callback, $page) { 
  2. global $wp_settings_sections; 
  3.  
  4. if ( 'misc' == $page ) { 
  5. _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); 
  6. $page = 'general'; 
  7.  
  8. if ( 'privacy' == $page ) { 
  9. _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); 
  10. $page = 'reading'; 
  11.  
  12. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);