Active Callback
The active_callback
can be use to set if field will be display under a condition. For more information you can read Customizer APIs.
Example
In this example the text
field will be display if toggle
is equal to true.
/**
* Creating a toggle field
*/
Yano::field( 'toggle', [
'id' => 'toggledb1c',
'label' => 'Do you want to show text field ?',
'description' => 'If you want to display the text.',
'section' => 'section_id',
'priority' => 1
] );
/**
* Creating a text field
*
* if the return value of the function in active_callback
* is true then text field will display else it will hide.
*/
Yano::field( 'text', [
'id' => 'textdb1c',
'label' => 'Text',
'section' => 'active',
'priority' => 2,
'active_callback' => function() {
// condition if the value
// of toggle is equal to true
if( get_theme_mod( 'toggledb1c' ) == true ) {
return true;
}else{
return false;
}
}
]);
Example 2: in this example the text field will only show at front page.
/**
* Creating text field
*/
Yano::field( 'text', [
'id' => 'textdb1c',
'label' => 'Text',
'section' => 'active',
'priority' => 2,
'active_callback' => 'show_in_front_page_only'
]);
/**
* Creating a function show_in_front_page_only
*/
function show_in_front_page_only() {
if( is_front_page() == true ) {
return true;
}
return false;
}