9

As per the codex, this question an probably any tutorial on the theme customiser out there, you get the value of a customiser field with the following code:

( function( $ ) {

    //Update site background color...
    wp.customize( 'background_color', function( value ) {
        value.bind( function( newval ) {
            $('body').css('background-color', newval );
        } );
    } );

} )( jQuery );

The problem is you can get that value, when its changed.

My question, is how (in a sane way) can you retrieve the value of another field in that same callback.

E.g.

( function( $ ) {

    //Update site background color...
    wp.customize( 'background_color', function( value ) {
        value.bind( function( newval ) {
            //Get value of field 'text_colour'
            //var text_colour = ??
            $('body').css('background-color', newval );
        } );
    } );

} )( jQuery );
6

Yes. wp.customize( 'header_textcolor' )():

( function( $ ) {

    //Update site background color...
    wp.customize( 'background_color', function( value ) {
        value.bind( function( newval ) {
            $('body').css('background-color', newval );
            var text_colour = wp.customize( 'header_textcolor' )();
            // ... now do something with text_colour
        } );
    } );

} )( jQuery );
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.