The customizer API offers active_callback
methods on both the control andd section classes. Basically you use either an conditional or a custom function to determine if a control or section is shown to the user.
If you want a section to appear only for pages, you would do somthing like this:
$wp_customize->add_section( 'wpse_283821_acme_pages', array(
'title' => 'Acme Pages Section',
'description' => 'Edit the ACME Pages Sections',
'priority' => 20,
'active_callback' => 'is_page',
) );
Or maybe a specific custom function:
$wp_customize->add_section( 'wpse_283821_acme_special_page', array(
'title' => 'Acme Special Page Section',
'description' => 'Edit the Specific ACME Page Section',
'priority' => 20,
'active_callback' => 'wpse_283821_acme_custom_callback',
) );
wpse_283821_acme_custom_callback() {
// Do your logic here
if ( true !== $condition ){
return false;
} else {
return true;
}
}
There are some questions on WPSE with good answers showing interesting uses of active_callback
. Check this one and this one. And there is this post with a use case just like yours.
I could just copy them here, but i Think it's worth taking a look at those questions, answers, comments and code to get a deeper understanding.