Support

Account

Home Forums General Issues Load JS script after ACF Reply To: Load JS script after ACF

  • The action you’re using, 'acf/input/admin_footer' only fires on the admin page where you edit the field groups. (Perhaps this is not what you want)

    To enqueue a script that fires on every admin page and loads after ACF, use this:

    wp_register_script('custom-acf-js', get_template_directory_uri() . '/library/scripts/script-js.js', ['acf-input'], '1.0.0', true);
    wp_enqueue_script('custom-acf-js');
    

    The five parameters in the 'wp_register_script' are:

    wp_register_script(UNIQUE_NAME, FULL_URL_OR_PATH, DEPENDENCIES_ARRAY, VERSION, LOAD_IN_FOOTER_BOOLEAN);
    wp_enqueue_script('custom-acf-js')

    as seen here: https://developer.wordpress.org/reference/functions/wp_register_script

    Putting ['acf-input'] in the dependencies array parameter tells the script it needs to wait until ‘acf-input’ has loaded first, which is ACF’s js script.

    If you want the script to load in other ways, on other pages, ACF also has other actions you can hook into, take a look here for those: https://www.advancedcustomfields.com/resources/#actions