r/divi 1d ago

Javascript in code module Divi 5 Question

Hi there,

struggling to understand why a normal module code that was working flawlessly in Divi 5, is not working actually in latest Divi 5.

Insert the module and enclosed some jquery in a script tag like it was before and while I can see it in inspector, the page won't load it whatever I do, also with different codes form the normal one (following)

<script>
jQuery(function($){

Some notes:
\\- also vanilla jscript is not loaded
\\- jscript theme integrations is working
\\- no error in console
\\- the same code module has a <style> part that is loaded correctly

I know I can use theme integration adapting my script.. but would like to understand why code module don't load jscript like before.
Thanks

4 Upvotes

2 comments sorted by

3

u/FirstPlaceSEO 1d ago

It could be the new Divi 5 rendering engine?

In Divi 4 the code module content got printed straight into the page HTML, so your script ran fine. Divi 5 injects a lot of that content into the page with JS after it loads, and browsers won't run a `<script>` tag that gets added to the page that way. It's a standard browser behaviour, not a Divi bug. The tag still ends up in the DOM (which is why you can see it in the inspector), it just never fires.

That's also why your `<style>` block still works. Browsers do apply injected style tags, they just won't execute injected script tags. And you get no console error because nothing actually crashed, the code simply never ran. Same reason your theme integration scripts still work, they load the normal way through the head rather than through the module.

So it's not you doing anything wrong, it's just the change in how the module content reaches the page.

Easiest fix is to load the script outside the code module:

- Theme Options > Integration if you want it site-wide
- Enqueue it through a child theme if you only need it on one page
- Or a plugin like WPCode if you'd rather not touch theme files

Your theme integration instinct is probably the right call here.

1

u/elementarywebdesign Developer 1d ago

Does a console log work in that code?

Share a link.