Support

Account

Home Forums Backend Issues (wp-admin) Uncaught Type Error

Solved

Uncaught Type Error

  • Hi there,

    Ever since I implemented the acf_form_head(); function in my functions.php, I’m getting the following JS errors:

    1) Uncaught TypeError: Cannot read property ‘post_id’ of null
    2) Uncaught TypeError: Cannot read property ‘hasClass’ of undefined (…)

    These errors only appear in the console when I’m logged into the backend.

    Here is my code that triggers the acf_form_head(); function:

    //add acf form head to header
    add_action( ‘init’, ‘brandpage_form_head’ );
    function brandpage_form_head(){
    acf_form_head();
    }

    Some other users posted the same issue on the forum but none of the solutions are working for me.

  • That is because ACF is trying to load the scripts that should only be loaded on the front end in the admin. The WP init hook fires on both the front end and admin. If you want to do this with a hook then you need to make sure you’re not loading an admin page.

    
    add_action('init', 'brandpage_form_head');
    function brandpage_form_head() {
      if (!is_admin()) {
        acf_form_head();
      }
    }
    

    I’m not 100% sure it will work though. init is an extremely early hook. Have you tested it on forms on the front end?

  • Thanks! It worked beautifully! I hope it stays this way.

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

The topic ‘Uncaught Type Error’ is closed to new replies.