The customize_section_active WordPress PHP filter allows you to modify whether a Customizer section is active or not.
Usage
add_filter('customize_section_active', 'your_custom_function', 10, 2);
function your_custom_function($active, $section) {
// your custom code here
return $active;
}
Parameters
$active(bool): Whether the Customizer section is active.$section(WP_Customize_Section): WP_Customize_Section instance.
More information
See WordPress Developer Resources: customize_section_active
Examples
Hide a specific section
Hide the “Colors” section in the Customizer.
add_filter('customize_section_active', 'hide_colors_section', 10, 2);
function hide_colors_section($active, $section) {
if ($section->id === 'colors') {
return false;
}
return $active;
}
Show a section only on specific pages
Show a custom section only on the front page.
add_filter('customize_section_active', 'show_section_on_front_page', 10, 2);
function show_section_on_front_page($active, $section) {
if ($section->id === 'your_custom_section' && !is_front_page()) {
return false;
}
return $active;
}
Disable sections based on user role
Disable a specific section for non-admin users.
add_filter('customize_section_active', 'disable_section_for_non_admins', 10, 2);
function disable_section_for_non_admins($active, $section) {
if ($section->id === 'your_custom_section' && !current_user_can('manage_options')) {
return false;
}
return $active;
}
Enable a section based on a theme option
Enable a custom section if a specific theme option is enabled.
add_filter('customize_section_active', 'enable_section_based_on_theme_option', 10, 2);
function enable_section_based_on_theme_option($active, $section) {
if ($section->id === 'your_custom_section' && get_theme_mod('your_theme_option') !== 'enabled') {
return false;
}
return $active;
}
Conditionally hide a section based on another section
Hide a custom section if another specific section is inactive.
add_filter('customize_section_active', 'hide_section_based_on_another_section', 10, 2);
function hide_section_based_on_another_section($active, $section) {
$required_section = $section->manager->get_section('required_section_id');
if ($section->id === 'your_custom_section' && !$required_section->active()) {
return false;
}
return $active;
}