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.
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
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:
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.
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).
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.
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.