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);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.