How can I add a custom module for Divi WordPress theme?
http://www.elegantthemes.com/gallery/divi/
Original modules are created in main-modules.php
Example:
class ET_Builder_Module_Gallery extends ET_Builder_Module { .... }
But the ET_Builder_Module
class is not accessible in my plugin, or in theme functions.php
7
Answers
You can do it modifying the Divi theme files (which is bad)
For example, you can modify main-modules.php to add a new module:
After that you need to add the panel for the customizer in functions.php:
If you do a search in functions.php you’ll find where to add it easily ๐
I want to try settling the little debate here.
class ET_Builder_Module_Custom_Module extends ET_Builder_Module {} actually works and main-modules.php can be modified freely IF a Child Theme is used.
I recently ajaxified a Divi Theme and after update everything worked like a charm.
Note: It’s always a good idea to check if there are updates on the files you use inside the child theme because sometimes you may need to update the child files also.
I hope this helped all future readers of this post.
HFGL with the new modules you are about to create ๐
Place below in your functions.php file. The include file (I called it custom-modules.php) will be a class that extends ET_Builder_Module (which is very similar to WP_Widget). Just open the file from Divi>>includes>>builder>>main-modules.php. Use any of the preexisting modules as an example or basis for your new one. Copy and paste into your custom-modules.php. New class names, make edits as needed, etc.
The code above didn’t work
The function needs to be called as well.
Here’s an example with working code from https://divi.space/blog/adding-custom-modules-to-divi/
Important note: The slug for your custom module must contain the string
et_pb_
, or it will be filtered out by the functionet_pb_allowed_modules_list()
.I was able to add a new Divi module using the following code (requires PHP 5.3+ for the anonymous function):
Inside the included file, copy and paste a
class
from thewp-content/themes/Divi/includes/builder/main-modules.php
file, then modify to suit your needs. See the example below (copy an actual class from the file mentioned to get the content of each method listed belowโฆ I like theET_Builder_Module_Code
class for simplicity’s sake):Most other solutions here are way too complex. The simplest way is to load your custom module in the divi specific action hook
et_builder_ready
, like this:You can find the full demo-code on github. Along with some instructions how to get it work in the all new Divi 3 frontend builder:
https://github.com/stracker-phil/divi3-vb-custom-modules/
For creating custom modules, I would use existing modules to create a design (layout), would save that design into Divi library and would use Text or Code modules and would write all HTML/jquery code there.
Like here, https://github.com/Skaidrius/Divi/tree/master/Layouts/Price-list