I have a javascript which reloads the page when content change is detected. This is the behaviour I want on the main site. But when I use the Wordpress Customizer I don't want this behaviour as it makes it very hard to work and Customize the page (the page tries to reload).
I tried deregistering the script and create a copy of the script without the reload function. This is how I did it:
add_action( 'wp_enqueue_scripts', 'customize_enqueue_appc_js' );
function customize_enqueue_appc_js() {
if ( is_customize_preview() ) {
wp_deregister_script( 'app-js' );
wp_enqueue_script( 'appc-js', get_template_directory_uri() . '/javascripts/appc.js', array('jquery'), false, true );
}
}
My idea here is to detect if you are on customizer with if ( is_customize_preview() ) {
and if true, deregister the javascript called app-js
, and enqueue the script appc-js
which hasn't got the reload function.
But this doesn't seem to work. Is it because the Customizer views the page without modifications? Are you able to do something like this? Modifying the page functions when viewed in Customizer?
Is there any other approach to this? Like doing this in jQuery?
999
and it seems to work. Will be doing some testing! Thank you @JacobPeattie