I have a small piece of JavaScript code that I want to put into my site made with the Divi theme. I made a child theme with a functions.php file and a js file. I put the following code in the functions.php file:
<?php
function wpdivi_theme_name_scripts() {
wp_enqueue_script( 'script-name', get_template_directory_uri() .
'/js/code.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdivi_theme_name_scripts' );
?>
In divi I used the code module to set up the HTML. I tested the code in this fiddle.
However when I use the same code on my WordPress site it doesn’t work. I tried a simple alert box in js but that doesn’t work either.
Can someone help me?
3
Answers
This is working for our wordpress site which is used DIVI theme. Could you please check with js file path.
If you are using “get_template_directory_uri()” function, the file should be there in parent theme js folder.
If you are using “get_stylesheet_directory_uri()” function, the file should be there in child theme js folder.
Try using the code module to enter the JavaScript directly. If you just surround your JS code in
<script>
tags inside the code module, it should work.Or, just go to Divi Settings > Integrations > Add script.