3

I am trying to run js function when customizer section is expended and cant seem to find any event to do so.

Something like this

wp.customize.bind( 'ready', function() {

    wp.customize.section.bind( 'expand', function() {
            console.log('hello');

    }); 

} );

or

wp.customize.bind( 'ready', function() {

    wp.customize.section.on( 'opened', function() {
            console.log('hello');

    }); 

} );

or anything that triggers when section is active/activated/expanded/opened.

Any help is appreciated!

2 Answers 2

3

Here it is

wp.customize.bind( 'ready', function() {

    wp.customize.section.each( function ( section ) { 

        section.expanded.bind( function( isExpanding ) {

            if(isExpanding){

                console.log(section);
            }


        });


    });
});
0

If you are targeting particular section, then you can do like:

wp.customize.section('title_tagline').expanded.bind(function (isExpanded) {
  if( isExpanded ) {
    // Do something here.
  }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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