Adding JavaScript / jQuery to the Divi Theme

There are several ways to add JavaScript (or jQuery – basically just of JavaScript with some additional features) code to the Divi Theme. One of the easiest ways is via the Divi Theme Options area.

Adding JavaScript / jQuery via the Divi Theme Options

If you go to the "Divi > Theme Options > Integration" tab from your WordPress Dashboard, you'll see the following:

You can use the "Add code to the < head > of your blog" box to add JavaScript / jQuery:

This box is actually for entering HTML code, but you can tell it you want to add JavaScript or jQuery code by surrounding your code in <script> and </script> tags.

For example, if you have the following code:

Then you would enter the following into the box:
So you'd have:

Then just save the options and your code should run when you view / preview your site. In this example, the code will just pop up a message saying "hello" whenever someone loads a page on your site. If you'd like to try a more useful example, please see this post on how to Make the Divi accordions closed by default.

This post may contain referral links which may earn a commission for this site

Divi Booster

Hundreds of new features for Divi
in one easy-to-use plugin


  1. Hello! Thanks for your rich contributions!
    I urgently need to know how I can configure so that the search only works if at least one word is entered, or rather 1 or 2 letters. And that it does not show the entire site or the entire category if you simply click on the search button if the field is empty. I don't want it to work with an empty field, if you click like this, it should show the 404 page. It will already have the message that you did not find anything because you did not type anything! or something like that! I hope you understand me.

    • Hey Carlos, I think I understand. The process will depend a bit on your search box and / or how you've set up the search results page. Is there any chance you're able to provide a link to the search box in question to check it out? One option that might work for you is to make the search boxes required fields, like so:

      That will stop the user being able to submit the search form at all, but note that it only works if the form is completely empty – typing a single space would bypass it. Not sure if that's a concern to you or not?


  2. Hi Dan! Super helpful, Thank you

  3. Hi Dan!
    Please help me out because I'm losing my head!

    I am trying to use some query (or javascript) to change an image when clicking a button (without reloading the page).

    Do you have any advise?


Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.