Title: Uncaught ReferenceError: wp is not defined
Last modified: February 25, 2021

---

# Uncaught ReferenceError: wp is not defined

 *  Resolved [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/)
 * hi there,
 * … sorry, but have to ask.
 * i am getting this error on every page with AO on.
    tried a myriad of options 
   but still completely unable to track it down. depending on AO settings there 
   are a lot more of this errors alike – up to 16 or 19 …
 * so this state gives me already the best result but the one remains, no matter
   what.
 * there are no errors with AO off.
    but then theres a ton of WP scripts inline 
   which makes me wonder anyway.
 * toolset already was a nightmare to get to work with AO… but everything works 
   fine so far in terms of functionality on frontend.
 * any quick look and a bit of help highly appreciated.
    thanks in advance.
 * –
 * EDIT:
    had to disable ‘aggregate inline js’ due to toolset (delayed response)
   again, along with ‘minify excluded js and css. functions alright, but now 16 (!)
   console errors again. source code looks crazy. excluded js scripts: `seal.js,
   js/jquery/jquery.js, js/jquery/jquery.min.js, views-frontend.js, toolset-common-
   es-frontend.js`
 * there seems to be something basic going comletely wrong – remember: no errors
   without AO.
    and… only site so far with this. curious about your verdict …
 * –
 * EDIT TWO:
    o.k. alarm from red to orange :/ adding `wp-includes/js` to exclusion
   solves the errors… but then theres all this nasty WPcode within source again.
   never seen this before in that way. something changed lately somewhere?
 * anyway still hoping for clearance 🙂 thanks
    -  This topic was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
    -  This topic was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
      Reason: typo
    -  This topic was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
    -  This topic was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Funcaught-referenceerror-wp-is-not-defined-3%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/page/2/?output_format=md)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14103057)
 * Indeed, `wp-includes/js` needs to be excluded due to [a major change in CF7’s frontend behavior](https://contactform7.com/2021/02/02/contact-form-7-54-beta/#overhaul-of-frontside-javascript)..:-/
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14103117)
 * …!?
 * so you are saying this error is all due to CF7??? no CF7 – no headache?
    strange–
   had already disbled it with no effect…
 * anyway – can’t leave this as it is! 77 requests in comparison to 22 without ‘
   wpincludes’. thats crazy!
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14103240)
 * will do some more tests tomorrow (21h09 here, have to call it a day) but that
   is my understanding yes ..
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14103282)
 * … same time here – so time to ditch off work for now, really 🙂
 * tomorrows another day. ill leave it as it is meanwhile and also will see again
   what the new day might bring.
 * wait for your response, thanks so far.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14105589)
 * OK, tested CF7 + AO on a blank (localhost) site and the good news is that that
   works with the default AO settings (so with `wp-includes/js/dist` excluded but`
   wp-includes/js` NOT excluded). That seems to imply that in your case there is
   another 3rd party (likely plugin) involved in things breaking. Did you install/
   update other plugins or did you recently started adding blocks (which can be 
   JS-heavy) on the frontend ?
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14105768)
 * … back on the hunting track too here.
 * meanwhile tested on staging and have to confirm it has nothing to do with CF7
   obviously.
    regarding some blocks thing too as the culprit that throws a lot 
   of primarily backend js … and gives tons of errors with AO or only one, depending
   on settings. and yes, completely rebuildt the page with block editor lately, 
   using generateblocks and toolset.
 * lately back to practically activating everything in AO including ‘aggregate inline
   js’, ‘add try catch block’ and ‘minify excluded css and js’ which gives me one
   last (mentioned) error. (not including inline js throws up to 16)
 * excluded scripts: `seal.js, js/jquery/jquery.js, js/jquery/jquery.min.js, views-
   frontend.js, toolset-common-es-frontend.js`
 * error from console (detected at line:1):
 *     ```
       1 ... || document.write( '<script src="https://xxx/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js?ver=STAGING-2.0.2"></scr' + 'ipt>' );</script> <script id='wp-api-fetch-js-after'>wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "https://xxx/wp-json/" ) );
       2 wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "9417a9fcb2" );
       3 wp.apiFetch.use( wp.apiFetch.nonceMiddleware );
       4 wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );
       5 wp.apiFetch.nonceEndpoint = "https://xxx/wp-admin/admin-ajax.php?action=rest-nonce";</script>
       ```
   
 * didnt find the bad guy yet … but anyway wondering what all this js that is visible
   without AO has to do within source code. youre able to see it in provided url.
 * still hunting … but running out of ideas.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14105793)
 * well, inline JS containing `document.write` is auto-excluded from being optimized(
   as document.write doesn’t work when not in the HTML). the code is part of the
   wp-polyfill in WordPress core and is also there on my CF7+AO testsite (where “
   also aggregate inline JS” is off).
 * my pov: be careful when doing everything with blocks, it can (and will, as you
   noticed) require quite a bit of JS being downloaded, parsed and executes, so 
   it _will_ always have a performance impact.
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14105922)
 * … so that much to the great new block editor … ;/
 * anyway: there are two plugins that seem to be involved when the error occurs.
   –
   CF7 – [Image Comparison](https://wordpress.org/plugins/image-comparison/#faq)
 * with both (or only one) active the errors occur – without theres neighter errors
   nor inline injection of wp js _(edit: o.k. partly, but much less)_. regardless
   whether AO is advised to also aggregate inline js or not…
 * so far at least. have to check it on live site again.
    -  This reply was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106028)
 * so you have the error even if only using CF7+AO?
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106059)
 * > so you have the error even if only using CF7+AO?
 * yep.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106073)
 * and if you -briefly- switch theme?
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106086)
 * ah, I see you don’t have `wp-includes/js/dist` in your JS exclusion list, which
   is excluded by default, I assume (hope) things are not broken with that exclusion
   active?
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106388)
 * > and if you -briefly- switch theme?
 * honestly didnt do so. its GeneratePress theme – in none of the numerous cases
   with errors during the last 5+ years this was the culprit. so did not test this,
   except from deactivating the pro version.
    wont expect any difference if doing
   so 🙂
 * > ah, I see you don’t have wp-includes/js/dist in your JS exclusion list, which
   > is excluded by default, I assume (hope) things are not broken with that exclusion
   > active?
 * nothing broken. everythings fine.
    in contrary things get worse if doing so with
   CF7 installed …
    -  This reply was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
    -  This reply was modified 5 years, 3 months ago by [dasigna](https://wordpress.org/support/users/dasigna/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106429)
 * so AO+CF7 with `js/dist` excluded (and “include inline JS” off) still gives errors
   for you?
 *  Thread Starter [dasigna](https://wordpress.org/support/users/dasigna/)
 * (@dasigna)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/#post-14106934)
 * > so AO+CF7 with js/dist excluded (and “include inline JS” off) still gives errors
   > for you?
 * no. but it gives still a too big amount of requests and lots of nasty inline 
   js in source 🙂
 * so goodbye to CF7. no headaches then!

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/page/2/?output_format=md)

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

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 18 replies
 * 2 participants
 * Last reply from: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-3/page/2/#post-14107023)
 * Status: resolved