active_callback
A callback function that determines the visibility of a specific control, whether to show or hide depending on a condition. For additional information about active_callback, please check the official Customizer API.
Attributes
This is the active_callback's comprehensive information.
| Type | Required | Default | Return |
|---|---|---|---|
| callable | no | null | boolean |
Basic Usage
EXAMPLE 1
In this example, the text control will be display if the toggle control's value is true.
// Toggle Control.
Handy::control( 'toggle', [
'id' => 'toggle_id',
'section' => 'layout_section',
'label' => esc_html__( 'Show Text Control?', 'textdomain' ),
'priority' => 1
]);
// Text Control.
Handy::control( 'text', [
'id' => 'text_id',
'section' => 'layout_section',
'label' => esc_html__( 'Text Control', 'textdomain' ),
'priority' => 2,
'active_callback' => function() {
// check the value of toggle.
return get_theme_mod( 'toggle_id' ) === true ? true : false;
}
]);
EXAMPLE 2
In this example, the text control will be display if the current active page template is front page.
// Text Control.
Handy::control( 'text', [
'id' => 'text_id',
'section' => 'layout_section',
'label' => esc_html__( 'Text Control', 'textdomain' ),
'priority' => 1,
'active_callback' => 'show_in_front_page_only'
]);
// Custom function.
function show_in_front_page_only() {
return is_front_page() === true ? true : false;
}