0

my script has one line wp.customize.control('control_id').deactivate()
the control DOES exist. as an evidence I inject the above code directly into the browser consol and it works (the control dissapears).
this is what I tried so far in functions.php:

add_action('customize_controls_enqueue_scripts',function(){
    wp_enqueue_script('customize_script', get_stylesheet_directory_uri() . '/customize.js', ['customize-controls'],false,true);
},999);

customize_controls_enqueue_scripts hook is the only one that makes sense to be used.
customize-controls is also the only dependency I could think of (an invalid dependency name will result into the script not being enqueued).
I also have the last boolean set to True to make sure the script is putted in the end.
and the last parameter 999 to make sure it's the last script to be added.
YET I keep getting in the console: Uncaught TypeError: Cannot read property 'deactivate' of undefined
I wait a second and inject the code directly in the console and it works.
anyone has an idea how to acheive a simple task that was not covered in the theme development handbook ?

1 Answer 1

1

after some research found that:

wp.customize.bind("ready", function () {});

is how to wrap the code properly to make sure everything is loaded before writing any algorithm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.