Get background color for Live Preview with Theme Customization API?

If you’re using the built in custom background stuff, it’s already all using postMessage.

So, just bind a function to the background_color message and adjust your border color accordingly.

Something like this, I expect:

wp.customize('background_color',function( value ) {
    value.bind(function(to) {
        jQuery('whatever').css('color', to ? to : '' );
    });
});

Obviously, change the jQuery call in the middle to adjust whatever you’re trying to adjust.

Some of the basics I didn’t cover, such as hooking that JS into the previewer and such, are here:

http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/

Leave a Comment