Wix Studio Custom Code Not Running

I added some custom JavaScript to my Wix Studio site, but the code doesn’t seem to execute consistently when the page loads.
What could cause custom code to work in the editor but not run correctly on the published site?

Can you share the code that you’re using? It’s very difficult to say without seeing it :slight_smile:

While you grab that code, a few things that commonly cause this exact symptom (works in editor, inconsistent on published site):slight_smile:

  1. If it’s in Settings > Custom Code (not Velo page code), check it’s set to load “On all pages” or the right specific page, and try switching “Place Code in” from Head to Body end, some scripts that touch the DOM fail silently in Head because elements haven’t rendered yet.

  2. If it’s Velo page code relying on $w(…), make sure it’s wrapped in $w.onReady(() => {…}). Code outside that runs before elements exist on first load, which looks “inconsistent” because it sometimes wins the race and sometimes doesn’t.

  3. Cookie/consent banners (including Wix’s own) block non-essential scripts until consent is given, if your code isn’t marked essential it may just not fire for visitors who haven’t accepted yet.

  4. After publishing, the CDN can serve a cached version for a few minutes, hard refresh (ctrl+shift+r) before concluding it’s still broken.

Once you post the snippet it’ll be quicker to pin down exactly which of these it is.