WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get/set the current previewURL within the Customizer.

I enqueue the script with the customize_controls_print_styles action:

function my_custom_script() {
    wp_enqueue_script( 'my-custom-script', plugin_dir_url( __FILE__ ) . '/js/my-custom-script.js' );
}
add_action('customize_controls_print_styles', 'my_custom_script');

In the script I try to set the previewURL and refresh the previewer when the user clicks on a specific customizer section

jQuery(window).load(function(){

    jQuery('#accordion-panel-my-custom-section').click(function(event) {
        // Hard coded URL for testing purposes
        wp.customize.previewer.previewUrl('http://example.com/test/');
        wp.customize.previewer.refresh();
    });

});

But it is not working. It only refreshs the previewer, but without changing the previewURL.

If I don't bind the function to a click event it works without problems:

jQuery(window).load(function(){

    // Hard coded URL for testing purposes
    wp.customize.previewer.previewUrl('http://example.com/test/');
    wp.customize.previewer.refresh();

});

What am I doing wrong?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.