John Fridinger, one of our readers and a Divi Children user, pointed out yesterday an issue he found while working on his new site with Divi 2.0 (thanks, John). He realized that when clicking on the “Load Layouts” button of the Page Builder, the available predefined layouts were duplicated.
It all looked like an issue that had to do with Divi child themes when John discovered that a ticket had already been opened at the ET support forum on this very same topic.
I wasn´t using predefined layouts myself, so I didn´t notice this issue until now. But when I clicked on “Load Layout” I found I had 7 repeated sets of predefined layouts on one of my Divi 2.0 test sites! Then I created a new child theme and nothing happened, but once I activated the new child theme I got yet another set of repeated predefined layouts.
Nothing harmful
I wanted to investigate where this problem came from, and I discovered that it is something that will happen every time a new child theme of Divi 2.0 is activated, no matter how you created the child theme.
Here is why:
Divi uses custom post types for layouts, which of course are saved on the WP database in the wp_posts table. As it is right now, every time you activate a new child theme, the Divi Page Builder code saves a new set of predefined layouts.
Because posts belong to your site and not to your theme, the repeated predefined layouts keep on growing every time you activate a new child theme and are always appearing there, even if you deactivate and delete your child themes.
It is nothing harmful but it sure is disconcerting, plus it is a bug and it should be fixed.
The issue explained
The culprits are a couple of functions in the layouts.php file, which is in the “layouts” subfolder of the Divi 2.0 theme (/Divi/et-pagebuilder/layouts/).
The first function is et_pb_update_predefined_layouts()
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function et_pb_update_predefined_layouts() { // don't do anything if layouts have been updated to 2.0 if ( 'on' === get_theme_mod( 'et_pb_predefined_layouts_updated_2_0' ) ) { return; } if ( 'on' === get_theme_mod( 'et_pb_predefined_layouts_added' ) ) { // layouts have been added already, delete default layouts et_pb_delete_predefined_layouts(); } // add predefined layouts et_pb_add_predefined_layouts(); set_theme_mod( 'et_pb_predefined_layouts_updated_2_0', 'on' ); } add_action( 'admin_init', 'et_pb_update_predefined_layouts' ); |
This function is hooked to admin_init
, so it will run when the admin area is accessed.
When a new child theme has just been created and activated, the theme mod et_pb_predefined_layouts_updated_2_0
does not exist yet, so the function will not return.
The same thing happens with the other theme mod: et_pb_predefined_layouts_added
doesn´t exist either, so the existing predefined layouts will not be deleted.
Nevertheless, a new set of predefined layouts will be created by calling another function: et_pb_add_predefined_layouts()
, hence the duplicated layouts are generated.
Elegant Themes to fix this issue
As a result of the ET support ticket I mentioned above, a member of the Elegant Themes support staff said that “we’ll modify that function and layouts will not be duplicated anymore. We’ll fix it in next theme update“.
So, as soon as Divi 2.0 gets updated with the next release, this issue is supposed to disappear.
What to do meanwhile
As I´ve said before, this issue is not harmful at all. That means that you can go on working on your Divi 2.0 site with no problems at all, except you will see your available predefined layouts repeated if you´re using a child theme.
Since I strongly recommend to always use a child theme if you´re planning to do any customization to your theme (that´s why I created the Divi Children plugin in the first place), I don´t want you to feel uncomfortable with this bug, so here are some ways to overcome it while you wait for the next Divi theme update from Elegant Themes:
Fix it modifying the parent theme
For the same reason that I encourage to use child themes, I don´t like modifying a parent theme. But in this particular case, since this issue is supposed to get fixed with the next update from Divi 2.0, you can tweak your Divi 2.0 because whatever change you do now it will be overwritten the next time you update Divi.
The fix for the parent theme is simple: you just need to change a line in the et_pb_update_predefined_layouts()
function of layouts.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function et_pb_update_predefined_layouts() { // don't do anything if layouts have been updated to 2.0 if ( 'on' === get_theme_mod( 'et_pb_predefined_layouts_updated_2_0' ) ) { return; } if ( ! get_theme_mod( 'et_pb_predefined_layouts_added' ) OR ( 'on' === get_theme_mod( 'et_pb_predefined_layouts_added' ) )) { // layouts have been added already, delete default layouts et_pb_delete_predefined_layouts(); } // add predefined layouts et_pb_add_predefined_layouts(); set_theme_mod( 'et_pb_predefined_layouts_updated_2_0', 'on' ); } |
Fix it with your child theme
You can also fix this issue without touching your Divi 2.0 parent theme. To do so, add the following code to the functions.php of your child theme:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/** * Divi 2.0 patch. * If the version of Divi being used is prior to 2.0, nothing is done. * If Divi 2.0 is used, this patch modifies the original et_pb_update_predefined_layouts() function in order to avoid duplicated predefined layouts. * If a Divi version greater than 2.0 is used, the duplicated predefined layouts issue should have been fixed by ET, so the original function is called. */ remove_action( 'admin_init', 'et_pb_update_predefined_layouts' ); function Divichild_pb_update_predefined_layouts() { if ( '2.0' == wp_get_theme('Divi')->get( 'Version' ) ) { if ( 'on' === get_theme_mod( 'et_pb_predefined_layouts_updated_2_0' ) ) { return; } if ( ! get_theme_mod( 'et_pb_predefined_layouts_added' ) OR ( 'on' === get_theme_mod( 'et_pb_predefined_layouts_added' ) )) { // layouts have been added already, delete default layouts et_pb_delete_predefined_layouts(); } // add predefined layouts et_pb_add_predefined_layouts(); set_theme_mod( 'et_pb_predefined_layouts_updated_2_0', 'on' ); } elseif ( '2.0' < wp_get_theme('Divi')->get( 'Version' ) ) { et_pb_update_predefined_layouts(); } } add_action( 'admin_init', 'Divichild_pb_update_predefined_layouts' ); |
Leave it to the Divi Children plugin
If you are not using a child theme yet and you don´t feel like writing code and messing with ftp, let Divi Children do the work for you.
At the moment I´m focused on the 2.0 version of this free plugin and, as I explained on my post Divi Children 2.0 sneak peek: Customizing Divi even further, without code, I´d planned to jump directly from Divi Children 1.0 to Divi Children 2.0. But as I encountered this issue I don´t want to keep you waiting so I´m releasing an intermediate 1.0.1 version to fix this bug.
That way, every child theme created by Divi Children will have the fixing code added to its functions.php, so you don´t have to worry about this issue.
Update: Divi Children 1.0.1 has already been released.
Final words
If you´re already experiencing this issue because you created and activated a child theme of Divi 2.0, all you have to do to make any of the above fixes work is to create and activate a new child theme.
Now if you happen to be thinking “What? I don´t want a new child theme fo Divi 2.0, I spent a lot of time and effort on my current child theme“, don´t worry at all. I didn´t mean you need to be using a new child theme: just create it and activate it. As long as you don´t give it a name that you´ve already used for a previous Divi child theme, the issue will get fixed and afterwards you can deactivate and delete that new “bogus” child theme and keep using your “real” child theme.
One more thing: I´ve checked it and found that this issue is not unique to Divi 2.0 (actually, the featured image I´m using for this post comes from a site running on Divi 1.7). Anyway, since there the affected code has changed with the release of Divi 2.0, I´m not addressing here any fixes for any version prior to Divi 2.0. If you are using an older version, you should update to Divi 2.0. You won´t regret it, by the way.
Divi 2.0 predefined layouts, Divi Children 1.0.1
- New Divi Children 3.0.10 update released - April 7, 2022
- New Divi Children 3.0.7 version for WordPress 4.9 - November 15, 2017
- Understanding Divi Children Output Mode - October 11, 2017
Luis
I’d noticed that, too, but thought I was just crazy, tired, or both. And, since about half the time I touch the php I end up with horrible things, I really appreciate you creating a fix!
Thank you!
Nicole
The funny thing is that I hadn´t noticed it myself, but then again that´s the real power of blogging (and of the WordPress community in particular): People helping each other.
About your php “horrible things”, just think about the other half of the time and you will get more and more confident. Just back up your files before you start doing anything that you fear could lead to a horrible result.
Anyway, nothing will explode if you do something wrong. Not even your computer.
LOL! You’re talking to a woman who managed to delete her operating system…Technically, according to an ever-helpful computer friend, I apparently deleted my partition. I still don’t know what the heck a partition is, much less how I managed to delete it.
But yes, I’m getting braver in the php. At least at incrementally deleting things I don’t want, once I figure out what they are…
But I agree about the WP world and blogging – it really is a community and that’s my favorite part.
😀
Also (how i found the bug) on my localhost idt does indeed duplicate. but after copying the site to another installation of wordpress (actually different localhost pc) it doesn’t show any layout…
You can hoose a layout but it wont register…. a blank pageBuilder is all you get!?