Customizing the Divi Theme: Where to Add Custom Code – Detailed Guide

Customizing the Divi theme with your own custom code allows you to push the boundaries of design and functionality. Below is a detailed guide on the various places you can add custom code within the Divi Theme, including what type of code goes where, why you might choose each location, and their respective benefits and drawbacks. Finally, I’ll touch on how to use these options to increase specificity in your code, ensuring your customizations are applied precisely where you want them.

Theme Options (Custom CSS and Integration Tab)

Custom Code in Divi Theme Options

Where to Add: Navigate to Divi > Theme Options in your WordPress dashboard. Here, you’ll find the “Custom CSS” box and the “Integration” tab.

Types of Code:

  • Custom CSS: For styling tweaks across your entire site.
  • Integration Tab: Ideal for adding HTML/JavaScript, such as Google Analytics code or custom scripts that need to run across the whole site.

Why Use This Location:

  • Custom CSS Box: Quick and easy way to apply site-wide style changes without affecting theme updates.
  • Integration Tab: Convenient for scripts that need to load on every page.


  • Easy access and management.
  • Changes apply site-wide, ensuring consistency.


  • Custom CSS applied here is loaded last, which can be both a benefit (overrides other styles) and a drawback (hard to override with specificity).


Custom Code in functions.php file

Where to Add: Within your theme or child theme’s functions.php file.

Types of Code: PHP snippets to add functionality or modify existing features.

Why Use This Location: Ideal for extending Divi’s functionality or integrating with other plugins. Changes here are applied globally.


  • Powerful way to customize or extend your site’s capabilities.


  • Incorrect code can break your site. Always use a child theme to prevent loss of changes on update.


Custom Code in styles.css file

Where to Add: In your theme or child theme’s styles.css file.

Types of Code: CSS for styling your website.

Why Use This Location: To define or override the default styling of your theme or specific parts of your site.


  • Keeps custom styles organized and separate from the theme’s original styles.


  • Requires understanding of CSS specificity to effectively override existing styles.

The Code Module

Custom Code in Divi Code Module

Where to Add: Directly within Divi Builder on posts, pages, or templates.

Types of Code: HTML, CSS, JavaScript, or shortcodes.

Why Use This Location: Perfect for adding custom code that only applies to a specific page or post.


  • Easy to use and doesn’t require editing theme files.
  • Great for one-off customizations.


  • Not suitable for site-wide changes. Each implementation is page-specific.

Child Themes

Custom Code in Divi Child Theme

Where to Add: Through a child theme’s functions.php, style.css, or adding new PHP files.

Types of Code: PHP, CSS, and potentially JavaScript.

Why Use This Location: Safeguards your customizations against theme updates.


  • Preserves customizations.
  • Organizes and separates custom code from the parent theme.


  • Requires creating a child theme and understanding theme hierarchy.

Divi Section/Rows/Modules Advanced Tab

Custom Code in Divi Sections, Rows, and Modules Advanced Tab

Where to Add: In the Advanced tab of any section, row, or module in Divi Builder.

Types of Code: CSS ID & Classes, and Custom CSS.

Why Use This Location: To apply specific styles or scripts to individual elements or sections.


  • High specificity for targeted customizations.
  • No need to edit theme files directly.


  • Can become cumbersome to manage for large-scale customizations.

Post or Page CSS

Custom Code in Divi Post or Page CSS

Where to Add: In the Divi Builder’s settings for individual posts or pages, under the Advanced > Custom CSS tab.

Types of Code: CSS specific to that post or page.

Why Use This Location: For styles that should only apply to a single post or page.


  • Directly targets the specific post or page.
  • Keeps page-specific styles organized.


  • Not efficient for styles that are reused across multiple pages.

Increasing Specificity in Your Code

To ensure your customizations target exactly what you intend, use specificity in your CSS and JavaScript. This means being more precise about which elements your code applies to, using IDs, classes, and nested selectors for CSS, and more targeted selectors for JavaScript. In practice, this could mean:

  • Using child themes and the style.css file for broad customizations with base specificity.
  • Leveraging Divi’s Advanced Tab or the Code Module for higher specificity where needed.
  • Applying CSS directly in the Theme Options or Integration Tab for site-wide rules, then overriding them on specific pages or modules with more specific selectors.

By thoughtfully choosing where to add your custom code and employing specificity wisely, you can tailor your Divi site to meet your exact needs without sacrificing performance or maintainability.

Wrapping Up

Leveraging custom code within Divi enables you to precisely tailor your website’s functionality and design. By strategically choosing where to insert your customizations—from site-wide CSS tweaks in Theme Options to targeted adjustments in Divi Builder’s Advanced Tabs—you can significantly enhance your site’s performance and aesthetic.

For those looking to quickly elevate their Divi projects, Divi Engine’s Code Snippets section is a fantastic resource. It offers an array of ready-to-use code snippets that simplify adding advanced features or fixing common issues. Explore these snippets at Divi Engine’s Code Snippets for practical, impactful enhancements.

Remember, effective customization combines strategic placement with savvy management of your code. With the powerful tools Divi provides and the additional resources from Divi Engine, you have everything you need to make your website truly stand out. Happy customizing!

Explore more from Divi Engine