Here is my code:
// Hooked to "after_setup_theme"
if(get_theme_mod('enable_vertical_header')) {
// init vertical header, register scripts, style, settings and output html in template
$vertical_header = new Vertical_Header;
}
I created a checkbox option "enable_vertical_header" (default value 0) in Customizer to turn on/off the vertical header, when I toggle the option, the live preview area refreshes, but nothing change.
By echo the value of "enable_vertical_header", I see it always null
, which make sense if on frontend. But in Customizer, should get_theme_mod
not return the real-time value?
Update: the Control code
function my_custom_text_settings( $wp_customize ) {
$wp_customize->add_section( 'my_section' , array(
'title' => __('My Section','mytheme'),
'priority' => 30,
) );
// Register the settings
$wp_customize->add_setting( 'enable_vertical_header', array(
'default' => 0,
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
// Add the controls
$wp_customize->add_control( 'enable_vertical_header', array(
'label' => __( 'My custom control', 'translation_domain' ),
'section' => 'my_section',
'settings' => 'enable_vertical_header',
'type' => 'checkbox',
'priority' => 10
) );
}
add_action( 'customize_register', 'my_custom_text_settings' );