How do I prevent a widget being updated in the customizer preview if a widget field fails a JS validation check? More generally, is there any actual documentation for the customizer JS API? (I mean real, proper api documentation rather than the few examples or sketchy descriptions)

  • 1
    I'm having the same problem. My widget has a checkbox field, every time this field is checked and unchecked the whole customizer preview reloads. Instead I want to use the js hooks like partial-content-rendered.
    – s_ferdie
    Commented May 30, 2016 at 9:36

1 Answer 1


Visit this link and read about transporter argument: https://codex.wordpress.org/Theme_Customization_API

Is that what you are looking for?

Here is an example for you:


add_action( 'customize_register', 'my_customizer' );
function my_customizer($wp_customize){
    $wp_customize->add_section( 'my_section', 
            'title' => __( 'My Custom Section', 'mytheme' ), //Visible title of section
            'capability' => 'edit_theme_options', //Capability needed to tweak
    $wp_customize->add_setting( 'my_setting', 
            'default' => 'option1', //Default setting/value to save
            'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
            'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
            'transport' => 'postMessage', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
            'label'    => __( 'My Custom Control', 'mytheme' ),
            'section'  => 'my_section',
            'settings' => 'my_setting',
            'type'     => 'radio',
            'choices'  => array(
                'option1'  => 'Option 1',
                'option2' => 'Option 2',
  • Could you provide an example of how to implement this please? The link is a great reference.
    – Howdy_McGee
    Commented Oct 28, 2016 at 19:13
  • Sure! Create a file customizer.php and put this code in: repl.it/EJES/2 Commented Oct 28, 2016 at 19:31
  • Thanks :D ! The rule of thumb for answers is that all the relevant information for the answer should be in the content itself and not in external links - those are additional references. That sounds like what he's referring to - there's an edit link underneath your answer to add in all the relevant information. There's also some documentation on code formatting ( usually just highlight and click the code button ). +1
    – Howdy_McGee
    Commented Oct 28, 2016 at 19:34

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.