0

I'm working on a theme which allows users to choose from a set of color palettes and I need to add more color controls so the user can change the background colors of sections of the site, which are controled based on the color palette. Until the user sets a custom color, I need the colors on these options to be updated (without refreshing) based on the color palette that is selected.

I need something simillar to Weston Ruter's answer on this question but I can't seem to figure out how to compare the current value and set the color according to it.

The following code updates the color without refreshing, but only to the option on the last "else" statement, whenever I try to compare the values it doesn't work.

wp.customize( 'themeb_scheme', 'themeb_footerbg', function( themeb_scheme, themeb_footerbg ) {
themeb_scheme.bind( function( value ) {

    if( themeb_scheme == 'light'){
        themeb_footerbg.set( '#eaeaea' );
    } else if( themeb_scheme == 'dark'){
        themeb_footerbg.set( '#323232' );
    } else  {
        themeb_footerbg.set( '#828282' );
    }

} );

} );

I have zero experience with jquery, the person that coded the layout is no longer working with us and I was asked to make those changes, so any help would be highly appreciated.

  • not totally sure but maybe you need themeb_scheme.value == not just themeb_scheme == ... otherwise try console.log(themeb_scheme); to see if you are getting what you need to match with. – majick Apr 14 '18 at 2:18
2

You're binding changes to themeb_scheme via an anonymous callback function with the parameter value as the new setting of themeb_scheme.

This should work:

wp.customize( 'themeb_scheme', 'themeb_footerbg', function( themeb_scheme, themeb_footerbg ) {
  themeb_scheme.bind( function( value ) {

    if( value == 'light'){
      themeb_footerbg.set( '#eaeaea' );
    } else if( value == 'dark'){
      themeb_footerbg.set( '#323232' );
    } else  {
      themeb_footerbg.set( '#828282' );
    }
} );

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.