Support

Account

Home Forums General Issues acf not defined – JavaScript API Reply To: acf not defined – JavaScript API

  • Sorry I did not get back to this sooner.

    When I build custom JS that extends ACF I use a separate JS file for this. I enqueue this script when ACF does so that it’s only loaded when ACF is.

    
    // this is lacking, but I want to highlight how to make your script dependent acf
    add_action('acf/input/admin_enqueue_scripts', 'my_acf_extension_enqueue');
    function my_acf_extension_enqueue() {
      $handle = 'my-handle';
      $src = 'url of script';
      
      // $deps is where we tell WP what scripts need to load first
      // https://developer.wordpress.org/reference/functions/wp_enqueue_script/
      $deps = array('acf-input');
      
      wp_enqueue_script($handle, $src, $deps, false, true);
    }