Where to Add Custom Code in Divi Theme

The Divi theme by Elegant Themes is one of the most popular WordPress themes for creating stunning and customizable websites. While Divi’s intuitive visual builder offers plenty of built-in features, sometimes you may need to add custom code to achieve a specific design or functionality. But where should you add your custom CSS, JavaScript, or PHP in Divi?

This guide will walk you through the best practices for adding custom code to Divi safely and effectively.

1. Using the Theme Options Panel for Custom CSS

The Divi Theme Options panel is one of the easiest and most straightforward ways to add custom CSS. This option is ideal for site-wide CSS modifications.

Accessing the Theme Options Panel

To add custom CSS in Divi’s Theme Options panel:

  1. Go to your WordPress dashboard.
  2. Navigate to Divi > Theme Options.
  3. Under the Custom CSS box (located in the General tab), paste your CSS code.

Add Custom Code in Divi theme panel

This method is perfect for quick tweaks, such as changing the color scheme, adjusting margins, or applying global styles. The Custom CSS box ensures your styles are applied across the entire website without needing external files

2. Adding Custom Code via the Divi Builder

For customizations limited to specific pages or modules, the Divi Builder provides an excellent solution. This method lets you target individual elements without affecting the rest of your website.

Adding Custom CSS to Modules like Section/Row/Module

Each module in the Divi Builder has an “Advanced tab” where you can “add custom CSS” Here’s how:

  1. Open the module you want to edit.
  2. Click on the “Advanced tab“.
  3. Locate the “Custom CSS” section and paste your code into the appropriate box (e.g., Before, Main Element, or After).

Custom CSS to divi Modules

This approach is ideal for styling unique modules, such as customizing a button or adjusting a single image gallery.

3. Using a Divi Child Theme for Advanced Customizations

For extensive modifications, especially PHP changes or scripts requiring deep integration, using a child theme is the safest option. A child theme allows you to customize your site while preserving your changes during theme updates.

Custom CSS

Once your site is complete and you’re ready to go live, I recommend transferring all your custom CSS to the style.css file in your Divi child theme. To do this, go to Appearance > Theme Editor, select your child theme from the dropdown menu in the top right corner, then click onstyle.css“.

Finally, paste your custom code at the bottom of the file.

Divi Child Theme

Adding Custom Code in a Child Theme

For PHP snippets, edit the “functions.php” file in your child theme. For instance, you can add custom post types or filters. To include CSS or JavaScript, you can create additional files (e.g., custom.css or custom.js) and enqueue them in “functions.php“.

Read More: How to Create a Divi Child Theme

Advantages of Child Themes

Child themes are ideal for developers who need to make substantial changes. They ensure that customizations are protected during updates, providing a stable environment for advanced edits.

4. Page/Post Settings

There may be instances where you just want to implement Custom CSS changes to a single page or post in the Divi Theme rather than the whole site. This tutorial will provide you with a step-by-step process on how to do just that.

add CSS code to a single page or post in Divi

5. Divi Theme (Theme file editor)

Finally, we have Divi, which is the least option for adding custom CSS. Avoid doing so, as any custom CSS you add will be wiped out and overwritten with every Divi update. In terms of hierarchy, this is the least reliable place to implement custom CSS.

Divi Theme Theme file editor

By following best practices and understanding when to use each approach, you’ll create a website that’s not only beautiful but also functional and future-proof.

That’s all for today!

Discover more by supporting me on
Buy Me A Coffee
Webflow vs Framer: Which No-Code Web Design Tool is Right for You?

Webflow vs Framer: Which No-Code Web Design Tool is Right for You?

Hey there, web design enthusiasts! If you’ve been diving into the world of no-code tools, you’ve probably heard of Webflow and Framer. These two platforms have been making waves in the web design community, but which one is the better choice for your next project?...

Webflow vs WordPress: Which One is Right for You?

Webflow vs WordPress: Which One is Right for You?

When it comes to building a website, Webflow and WordPress are two of the biggest names in the game. Both offer powerful tools to help you create a stunning online presence, but they cater to different audiences and skill levels. So, which one should you choose? Let’s...

How to Optimize Your Webflow Site for Speed & Performance

How to Optimize Your Webflow Site for Speed & Performance

A slow website is a fast way to lose visitors. No one likes waiting for a page to load, and if your Webflow site isn’t optimized for speed, you’re likely driving away potential customers before they even see what you have to offer. The good news? Webflow is built for...