So there’s 2 Customizer specific hooks depends on what exactly you’re trying to do.
The customize_controls_enqueue_scripts
is exactly like wp_enqueue_scripts
but it enqueues in the control panel ( left side ) frame. I suggest requiring customize-controls
scripts to make sure your script has access to them:
function theme_customizer_control_scripts() {
wp_enqueue_script( 'scirpt-slug', $scirpt_url, array( 'jquery', 'customize-controls' ), false, true );
}
add_action( 'customize_controls_enqueue_scripts', 'theme_customizer_control_scripts' );
- The Codex –
customize_controls_enqueue_scripts
- Dev Resources
The 2nd is customize_preview_init
which is where you’ll be able to modify your customizer preview panel as controls change:
function theme_customizer_preview_scripts() {
wp_enqueue_script( 'scirpt-slug', $scirpt_url, array( 'jquery' ), false, true );
}
add_action( 'customize_preview_init', 'theme_customizer_preview_scripts' );
- The Codex –
customize_preview_init
- Dev Resources
If you’re trying to change elements on the fly from controls to previewer you would need to enqueue the following script / add the following code to the previewer side of things. Once enqueued there you should have access to the wp.customize
object and can use jQuery as normal:
jQuery( window ).ready( function( $ ) {
// WP Customize Manager JS Object
var customizer = wp.customize;
// Assign things by the Customize Control ID
customizer( 'parallax_effect', function( control ) {
// Bind some kind of event
control.bind( function( value ) {
if( 'zoom' === value ) {
// Do something
$( 'body' ).addClass( value );
}
} );
// This will set the initial state. It's very heavy
// I do not recommend doing this for multiple controls
// Or at all... But it exists so I'm adding it to this answer
$( control ).trigger( 'change' );
}
} );