1

This is the JavaScript code used in the underscores theme to preview any change of the setting value without reloading the previewer:

// Site title and description.
wp.customize( 'blogname', function( value ) {
    value.bind( function( to ) {
        $( '.site-title a' ).text( to );
    } );
} );

Instead of using this (from the code above):

    value.bind( function( to ) {
        $( '.site-title a' ).text( to );
    } );

Can I use the following?

    function ( value ) {
        $( '.site-title a' ).text( value );
    }
  • If I am correct, you want to know what the difference is between the one method and the other, maybe update your question a bit so it becomes clearer, – Tobias Beuving Nov 7 '15 at 23:06
  • I am very curious too now :) – Tobias Beuving Nov 7 '15 at 23:07
  • the first code work for me but i want to understand it – Elidrissi simo Nov 7 '15 at 23:20
  • Me too, I upvoted the question, now let's hope someone smart passes by and sees it :) – Tobias Beuving Nov 8 '15 at 11:08
0

In short - yes you can. Whether it's a smart thing to do depends on your demands. If you want to use the functionality for customization of a theme you can read about the API here.

  • Thanks Tobis but what is the purpose of using .bind ? – Elidrissi simo Nov 7 '15 at 19:41
  • Well, good question - since you asked I am digging and reading up everything I can about bind. I tried setting the value of (.site-title a) from the console to check if there was some 2 way binding going on, but no success. Only thing I can tell you is that the code is not exclusive to the underscores theme, it's the general way to update screen elements with the customization API codex.wordpress.org/Theme_Customization_API – Tobias Beuving Nov 7 '15 at 23:04
  • i did the same and nothing was displayed in the console – Elidrissi simo Nov 7 '15 at 23:17
  • My guesses are - that with the bind method an internal variable 'blogname' also gets set, in order to post it lateron via ajax. Or (and this is sounds the most logic) that there is no internal variable and this way the program relates the ('.site-title a' ).text with blogname when posting the value with ajax. – Tobias Beuving Nov 8 '15 at 11:03
  • in this post wpshout.com/polishing-the-wordpress-customizer-experience: " For our purposes, the important thing about this use of the class is that we’re binding a function to value. That function is using function( newval ) {} to set the property in the page preview to the newval, the value of the option we’re “catching” with value.bind()." – Elidrissi simo Nov 8 '15 at 12:50

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.