$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - wp.customize.bind ready event not fired|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - wp.customize.bind ready event not fired

matteradmin10PV0评论

I'm trying to add some javascript to my theme customizer. My JS file is loaded no problem and my document ready event works but wp.customize.bind() isn't calling my callback.

jQuery(document).on('ready', function(){
  console.log('binding')
  wp.customize.bind('ready', function(){
    console.log('ready')
  })
})

binding gets outputed to the console but ready does not.

What am I missing? there seems to be little to no documentation on using the javascript here.

I'm trying to add some javascript to my theme customizer. My JS file is loaded no problem and my document ready event works but wp.customize.bind() isn't calling my callback.

jQuery(document).on('ready', function(){
  console.log('binding')
  wp.customize.bind('ready', function(){
    console.log('ready')
  })
})

binding gets outputed to the console but ready does not.

What am I missing? there seems to be little to no documentation on using the javascript here.

Share Improve this question asked Sep 12, 2016 at 8:36 ArcathArcath 2391 gold badge3 silver badges9 bronze badges 2
  • This might help: wordpress.stackexchange/questions/211779/… – cjbj Commented Sep 12, 2016 at 12:27
  • I have the exact same problem. Binding logs, ready not. That there is so little documentation available to the javascript API is really frustrating. – Snowball Commented Sep 16, 2016 at 4:55
Add a comment  | 

2 Answers 2

Reset to default 5

Do not put the Customizer ready event handler inside of the jQuery event handler. The Customizer ready will trigger at jQuery ready, so you are adding the event handler too late. Just do:

wp.customize.bind('ready', function(){
    console.log('ready');
});

Your JS needs to be enqueued with customize-controls script as its dependency. Enqueue at the customize_controls_enqueue_scripts action.

I had same problem. The reason it was not binding for me was because I had this error "Uncaught TypeError: Cannot read property 'unsync' of undefined" on my console.

It was caused because I removed the header_textcolor settings from the theme template by using $wp_customize->remove_setting( 'header_textcolor' ); but it was still being referenced in the js.

After fixing this, bind worked as intended.

Post a comment

comment list (0)

  1. No comments so far