WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Class Reference/WP Customize Manager/add section

Description

Adds a new section to the Theme Customization admin screen. Sections are convenient ways to group controls logically.

This is a method of the WP_Customize_Manager class and can only be accessed through the $wp_customize object within the customize_register action hook.

Usage

function mytheme_add_section( ) {
   $wp_customize->add_section($id, $args);
}
add_action( 'customize_register', 'mytheme_add_section' );

Parameters

$id
(string) (required) A unique slug-like string to use as an id.
Default: None
$args
(array) (required) An associative array containing arguments for the control.
Default: None

Arguments

title
The visible name of a controller section.
priority
This controls the order in which this section appears in the Theme Customizer sidebar.
description
This optional argument can add additional descriptive text to the section.
active_callback
This optional argument can show or hide section based on currently viewed page. Example: 'active_callback' => 'is_front_page'.

Default Sections

WordPress does include a few built-in sections. If you want to use any of the existing, built-in ones, you don't need to declare them with add_section(). Instead, refer to them directly. The following sections are built-in...

  • themes - <name of the theme>
  • title_tagline - Site Identity
  • colors - Colors
  • header_image - Header Image and Site Icon
  • background_image - Background Image
  • static_front_page - Static Front Page (shown only if there is at least 1 page)

Example

Adding a theme section (within the 'customize_register' action) might look like this:

$wp_customize->add_section( 'mytheme_new_section_name' , array(
    'title'      => __('Visible Section Name','mytheme'),
    'priority'   => 30,
) );

Related

See also index of Class Reference and index of Function Reference.