Support

Account

Home Forums Front-end Issues acf_form front end Image or gallery field error : "wp.media is undefined"

Unread

acf_form front end Image or gallery field error : "wp.media is undefined"

  • I have identified the reason for this error and I’m sharing it here in case it can save time to anybody with a similar problem.

    I created a font-end form using acf_form and the form in question has an Image field.
    But when the user clicks the “add media” button of the field, nothing happens and the console displays the error Uncaught TypeError: can't access property "query", wp.media is undefined.

    FYI if you have a similar problem don’t forget to troubleshoot you website by using a default WP theme and disabling all extensions except ACF. RE-enable all extensions and lastly theme until it breaks again to identify the culprit.

    In my case it was caused by a companion plugin for the theme I use that has a function going as follow:

    
    // remove the mediaelement
    function deregister_styles() {
        wp_deregister_script( 'wp-mediaelement' );
        wp_deregister_style( 'wp-mediaelement' );
    }
    
    add_action( 'wp_print_styles', 'deregister_styles', 100 );
    

    this is obviously problematic and will break things.

    Hope this will help someone someday. Cheers.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.