Home Forums Backend Issues (wp-admin) ReferenceError: acf is not defined


ReferenceError: acf is not defined

  • Greetings from Belgium! First of all: love your plugin!

    I have some trouble with a project due to an upgrade from ACF 3.x to 4.2.2. This is a project on WordPress 3.6.1 with a custom plugin.

    In this custom plugin I show the acf fields on the edit page. Everything works fine except for the wysiwyg editors – they don’t appear due to a javascript error:

    ReferenceError: acf is not defined
    acf.post_id = 0;
    admin....did=382 (regel 220)

    It seems as though input.min.js (and fields.min.js?) doesn’t get included. With ACF version 3.x I had a acf_form_wp_head() that dealt with the correct includes – it seems as though this doesn’t work anymore in ACF version 4.x.

    Do I have to use an other function to include the right javascript files?

  • Hi @annelyze

    I can’t remember when that function was fazed out, but you should be using the acf/input/admin_head action instead.

    Am I right in assuming that you are running the acf_form_wp_head function in the admin_head action?

    If so, all you need to do is change to this:



  • Hello Elliot

    Thx for the quick reply. This however didn’t fix the problem.

    If I take a look at the acf_form_wp_head function I see the following:

    function acf_form_wp_head()

    So in fact I already did the do_action part, only from within a function (which I called in my custom code).

    I’ve tried some other placements for the do_action in my code but this didn’t work either. I’m not a frequent WordPress user so I’m not sure what to try next.

    This is the current situation:
    I’ve added a hook to a custom function:
    add_action('admin_head', 'cjobs_admin_head');

    In that function I’ve put the do_action:

    function cjobs_admin_head()

    This is already something different than the code I used in version 3.x. In that version all I had to do was call the acf_form_wp_head function just before parsing the acf fields.

    This is the acf_form_wp_head function in version 3.x:

    function acf_form_wp_head()
    	// global vars
    	global $post, $acf;
    	// Style
    	echo '<link rel="stylesheet" type="text/css" href="'.$acf->dir.'/css/global.css?ver=' . $acf->version . '" />';
    	echo '<link rel="stylesheet" type="text/css" href="'.$acf->dir.'/css/input.css?ver=' . $acf->version . '" />';
    	// Javascript
    	echo '<script type="text/javascript" src="'.$acf->dir.'/js/input-actions.js?ver=' . $acf->version . '" ></script>';
    	// add user js + css
  • Hi @annelyze

    Perhaps you should take a look at the /core/controllers/input.php file. This will give you examples of how to use the actions and where to use them for ACF to render the necessary scripts.


  • Hi Elliot

    Still no luck on getting the right scripts to load at the right moment 🙁
    I must be overlooking something but I just don’t see what.

    I’ve solved the problem for now by loading them manually.

    Thanks for your time!

  • I just fixed the issue on ACF 4.4.1 version

    acf not defined…

    The problem was in loading the scripts in the correct order.

    What I’ve done is:

    open “wp-content/plugins/advanced-custom-fields/acf.php” and go and comment the lines from 524 to 528 the init of the input.min.js then open “wp-admin/admin-header.php” and right after the <title></title> include these 2 scripts:

    <script type="text/javascript" src=""></script>
    <script type='text/javascript' src=''></script>

    *move the input.min.js into new js folder into js to not get conflicts:)

    save all the changes and you will see you wouldn’t encounter this issue just reload the CPT add new/edit page and there you go.

    Hope this will solve everybody’s issue, it’s only temporary once we get an update from @elliot 🙂 hope the 4.4.2 will fix this issue.

    Cheers mates.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘ReferenceError: acf is not defined’ is closed to new replies.