Divi PHP Code Module

Add and run PHP code in your Divi pages

Adds a PHP code module to Divi
Display your code’s output in your Divi pages
Preview and debug the code in the visual builder

Lifetime license. Nothing more to pay.
Automatic updates. 90 day money back guarantee.

Easily Add PHP Code to your Divi Pages

Introducing the Divi PHP Code Module, the ultimate tool for harnessing the power of PHP right within the Divi Builder. With this easy-to-use Divi module, you can seamlessly add and run PHP code directly in your Divi pages and posts, providing endless possibilities for customization, automation, and dynamic functionality.

Adds a PHP Code Module

With Divi PHP Code Module you get a new "PHP Code" module in the Divi Builder that gives you everything you need to quickly and easily add PHP code into your Divi pages. 

Unlike the native Divi "Code" module, which only allows static HTML and JavaScript, the Divi PHP Code module allows you to go further and dynamically generate content using using PHP. 

Divi PHP Code module makes adding PHP code simple – more messing about with child themes, or trying to wrap your PHP code in shortcodes.

Enter your PHP Code… and you're done


Simply insert the PHP Code module into your page, add PHP code in the module's settings, and then when the page is viewed the PHP code will run and its output will be displayed where the module is on the page… like this:

An Example PHP Code Module

Hi, I am a Divi PHP Code Module!

Test your code in the Visual Builder

You can quickly test and run your code right from in the visual builder. Simply click on the green "Play" button beside the PHP Code box to run your PHP code and see how it will look in the final page. 

Built-in Debugging and Error Handling

With the built-in Debug option, you have complete control over error display. Easily toggle the display of errors on or off, allowing you to efficiently troubleshoot and resolve any issues that may arise. Divi PHP Code Module incorporates robust error handling, ensuring that even if an error occurs, your website remains intact and functional.

No more broken layouts, blank screens, or frustrated visitors – just smooth and reliable performance.

Designed for Security

The Divi PHP Code Module has been carefully designed with security in mind, ensuring that your PHP code runs smoothly while protecting your website. With Divi Role Editor integration and cryptographic integrity checking, the module is designed to ensure that you have full control over who gets to run code on your site.


With the power of PHP in a Divi Builder module, your capabilities are essentially limitless. But to get you started thinking about how you can use the Divi PHP Code Module in your own projects, here are a few small examples:

Creating Tables

Stop manually editing tables! Instead, load the data directly the original source, and display it as a HTML table, formatted exactly how you like it.

Sample Table

John 25 New York
Sarah 32 London
Michael 28 Paris
Emily 30 Sydney

Text Effects

Make your text and headings stand out! With the power of PHP you can easily transform your text in ways that are difficult with CSS alone.

Text Gradient Effect

Welcome to the Digital World!

Display Dynamic Information

Easily display information from your database or other sources (e.g. APIs). 

WordPress Stats

Dan has written 505 posts and 2753 comments on this site (and needs a rest).

Creating Forms

Add forms to your page with a mix of HTML and PHP code. 

My Custom Form


How is this different from the Divi's own Code Module?

The built-in Divi Code module and the Divi PHP Code module by Divi Booster serve a similar purpose of allowing custom code to be added to Divi layouts. However, there is a key difference in the languages they support.

The built-in Divi Code module can only handle static HTML and JavaScript code.

Divi PHP Code module, on the other hand, also allows PHP code to be added. PHP is a server-side scripting language that enables dynamic content generation. As such, it allows you to execute custom server-side logic and generate dynamic content for your layouts, something that can't be achieved through the standard Divi Code module..

By supporting PHP, the Divi PHP Code module gives you more flexibility and power. It opens up possibilities for integrating with external systems, fetching and displaying dynamic data, performing advanced calculations, etc.

So is any PHP code I add secure?

No, not necessarily. The PHP Code module aims to provide a secure environment for adding PHP code to the Divi Builder, but can't guarantee the security of any code you add.

The Divi PHP Code module is designed to only run PHP code that has been added through the visual builder interface – when code is added in this way, a keyed cryptographic hash is added which is checked before the code is actually run. Additionally the permissions set in the Divi Role Editor are checked to ensure that the user has been granted access to use the module, and by default only the administrator is granted permission – other user roles must be given specific permission to use the module. Together, these mechanisms seek to prevent anyone adding or altering code without permission.

But what the PHP code you add actually does is entirely up to you – you can add secure code or insecure code, and the responsibility for that rests with you. The functionality of added code isn't restricted by the module in any way, so you are free to use the full power and functionality of PHP. But this means you also need to be aware of the security implications of the code you add. While you could add code to let anyone run any command on your server, or to delete your database, doing so would probably be a very bad idea. So follow secure coding principles when adding code. For example, make sure you understand what the code does, avoid accepting user input (or perform whitelist validation on it, if you must), and appropriately escape data before it is used. 

With the Divi PHP Code module's built-in security mechanisms and good security practices on your part, there shouldn't be any issues. I do, of course, recommend taking regular backups as a standard and sensible way to further protect your site and data.


When is the PHP code run?

The PHP code is run in the module's render() function. This means that it runs at the point in the page where the module output is being generated. As such, it runs after WordPress, Divi and any installed plugins have been loaded, which means that your code can take advantage of the functions / classes that they add. There are some things that PHP code added via the module will be too late to affect – for example, it won't be able to add filters / actions to hooks which are run before the page generation begins. 

Get Divi PHP Code Module

Increase your productivity. Build better websites. Start today with Divi PHP Code Module. 

Divi PHP Code Module

Automatic updates. No recurring fees.
90 day money back guarantee.

Got a Question?


  1. I see the special expires today. Thus I need to rush. The best plugin I ever bought was the divi booster. With this php module (I think it can open up a whole new world) I might be able to write a payroll system? i.e I see your sample with the csv code. But will I be able to create database tables. I'm really old school and practically ancient. My language of choice (don't laugh) is Delphi 5 in which I regard myself an expert and prior to that (now don't burst out laughing) was clipper.

    I get the impression new languages seems to go back to the early 80's when we still used assembly. I suspect AI will go straight for machine code, and not bother with languages as we know them.

    My question. Will I be able to manipulate real database tables?

    • Hey Theo,

      I'm really glad you like Divi Booster :)

      Please don't rush – if you do miss the deadline just send me a message and I'll ensure you get the discount.

      Yes, you can absolutely create database tables. You have the full PHP functionality at your disposal so you can use the PHP sql functions. You also have WordPress's database functionality available to you, i.e $wpdb.

      So to list the current database tables, you could place this in the Divi PHP Code module:

      global $wpdb;

      And to actually create a database table you could paste in something like this:

      global $wpdb;
      $table_name = $wpdb->prefix . "my_table"; 
      $charset_collate = $wpdb->get_charset_collate();
      $sql = "CREATE TABLE $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
        name tinytext NOT NULL,
        text text NOT NULL,
        url varchar(55) DEFAULT '' NOT NULL,
        PRIMARY KEY  (id)
      ) $charset_collate;";
      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );

      This is very closely based on the code in this WordPress codex entry. I've tested it and can see it works.

      One thing I'd point out is that PHP code added via the Divi PHP Code module will be executed every time a page containing the module is viewed (unless caching is involved). So you may want to ensure your code can handle that without issues, or restrict modules that actually build the database to private pages.

      Good luck with the payroll system and give me a shout if you have any further questions about it.


      P.S. I started out on C64 Basic so I'm not sure I can legitimately laugh at the Delphi / clipper developers of the world ;)

  2. Hi,

    Your PHP module looks great.
    Can it be used to insert PHP template files into pages (eg something like /templates/testimonials-section.php)

    • Thanks Donal. Yes, you can absolutely do this, with an include() statement. I've put up a post with an example for you:

      Including a PHP Template File in Divi Builder

      Basically if you include the template it will be loaded and executed. You can also pass variables into the template, as explained in the post.

      I hope that helps, but give me a shout if you have any questions about it. Thanks!

      and you can even pass variables to the template.


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 *.