Site icon Hip-Hop Website Design and Development

Utilizing jQuery to retrieve customizer worth

I’m making an attempt to make use of jQuery to retrieve a theme choices (customizer) worth:

    $wp_customize->add_setting( 'header_fixed', array(
        'default'   => true,
    ) );
    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'header_fixed', array(
        'label'     => __( 'Allow mounted navigation?', 'theme' ),
        'part'   => 'header_section',
        'settings'  => 'header_fixed',
        'kind'      => 'checkbox',
        'precedence' => 40,
    ) ) );

If the above worth is true, then the header aspect shall be mounted place. If not, it will likely be relative place (a category shall be added, or not, with jQuery). I am not terribly competent with jQuery, so the next is predicated on what is available in customizer.js, from _s:

    wp.customise( 'header_fixed', perform( worth ) {
    worth.bind( perform( to ) {
        if ( 'true' == to ) {
            $( '#header-inner' ).addClass( 'mounted' );
        }
    } );
} );

I have been inserting this in customizer.js as doing so elsewhere ends in an error: ‘wp’ just isn’t outlined.

Edit* I am enqueuing the script as follows:

perform theme_customize_preview_js() {
wp_enqueue_script( 'theme-customizer', get_template_directory_uri() .  '/js/customizer.js', array( 'customize-preview' ) );
} 
add_action( 'customize_preview_init', 'theme_customize_preview_js' );

Edit** This appears to not be fairly attainable right now, so I ended up doing it with PHP:

<?php if ( '' != get_theme_mod( 'header_fixed') ) echo 'mounted'; ?>

Thanks!