add_settings_section

Home » Functions » add_settings_section

Function Name: add_settings_section

As the name suggests, the add_settings_section function is used to add a new section to the WordPress settings page. This function is commonly used in WordPress plugin development to group related settings fields together in a single section.

The add_settings_section function accepts four parameters:

  1. $id – The unique ID of the section.
  2. $title – The title of the section.
  3. $callback – A callback function that generates the HTML for the section description.
  4. $page – The slug of the settings page to which this section belongs.

Here’s an example usage code:

function my_plugin_settings() {
    add_settings_section(
        'my_section_id',
        'My Section Title',
        'my_section_description',
        'my_plugin_options'
    );
}
add_action( 'admin_init', 'my_plugin_settings' );

function my_section_description() {
    echo 'This is a description of my plugin settings section.';
}

In this example, we define a new section for the my_plugin_options settings page using the add_settings_section function. The section is assigned a unique ID of my_section_id and a title of My Section Title. The section description is generated by the my_section_description function.

Note that the add_settings_section function does not actually create any settings fields. It only defines a new section to which fields can be added using the add_settings_field function.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.