Support

Account

Home Forums General Issues Javascript API

Helping

Javascript API

    • bensen

    • October 14, 2019 at 5:32 am

    Hi,

    i just read the API Docs but i was wondering how to set it up that it works?

    When i try to access the acf object from a external js file, directly in the header or in the footer i always get “acf is not defined”.

    Thanks in advance for your help.

    Ben

  • When you enqueue a script you need to make sure you set the $depends argument.

    
    wp_enqueue_script($handle, $src, array('acf-input'), $version, true);
    

    it is best to enqueue your scripts on the ‘acf/admin_enqueue_scripts’ hook

    
    add_action('acf/admin_enqueue_scripts', 'my_acf_scripts');
    function my_acf_scripts() {
      // enqueue scripts see above
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.