Adding Controls to Theme Customizer If Certain Page Template is Active

How to Conditionally add controls on Theme Customizer panel. Conditional like is_page() or is_page_template() obviously does/will not work because the page is being shown is customize.php.

Code Example

add_action( 'customize_register', 'my_theme_customize_register', 11 );

function my_theme_customize_register($wp_customize){
    if( is_page_template('my-template.php'){
        // add special control
    }
}

Another observation is, customization setting control panel does not refresh when we switch to pages. It uses ajax to load theme preview. So, I guess theme customizer did not intend to use for post/page specific settings. So, am I hitting a dead end?

0

Leave a Comment