How to add the Divi Builder AND Divi Library to ANY CPT

May 15, 2017 | Divi, PHP, Themes, Time Savers, Tutorials, Wordpress | 8 comments

I’ve been working on the Divi Cloud project for a month or two now and am optimising the server side of things. A side that no one except me cares about although something that really matters to those who use the service. The server plugin keeps things fast and effective and so it’s rather important. Data entry for us into the Divi United site is laborious at present and so I wanted to do something about this. I won’t go into detail about exactly what it does and doesn’t do (trade secrets and all that) however. I did come across the need to use the Divi Builder on a custom post type (CPT).

This method has been publicised heavily by various bloggers.. some doing it the ‘right way’ and others missing the point entirely… such is the nature of the web! I came across an official Elegant Themes blog post from mid 2016 explaining how to do it and in the comments someone asked why their Divi Library items are not showing in the CPT. The reason given was that CPTs have their own library (sort of) and as such those library items made for posts/pages can therefore not be used for a CPT.. such as projects or products.

So. I did what I always do and went digging around the code. As it turns out I needed the Divi Library to load in layouts and therefore needed to work around this limitation. I found it within a few minutes. Using a simple filter you can make the CPT think that it needs to pull from the post/page library instead of it’s own. This is in no way a perfect solution but seems to be bug/error free and gets your library items to show in the CPT.. or it did for me at least.

So the original code to enable the builder on the post type is as follows:

function sb_et_builder_post_types( $post_types ) {
 $post_types[] = 'your-cpt';
 
 return $post_types;
}
add_filter( 'et_builder_post_types', 'sb_et_builder_post_types' );

And the code to make the Divi Library ‘work’ is this:

add_filter( 'et_pb_show_all_layouts_built_for_post_type', 'sb_et_pb_show_all_layouts_built_for_post_type' );

function sb_et_pb_show_all_layouts_built_for_post_type() {
 return 'page';
}

Add both to your child theme functions.php file and you should instantly see the results!

A Donate Button!

8 Comments

  1. gdrayson

    Your knowledge of Divi is getting so good that soon Elegant Themes will be asking you questions 🙂

    Reply
  2. googlereu

    I care about the server side, honest!

    Reply
  3. Darren Woodley

    Nice work!

    Reply
  4. Liza

    Thank you for this! Been pulling my hair out over this one.

    Reply
  5. Sohaib Aziz

    Wow seriously you rock Man !

    Reply
  6. David Klhufek

    Thank you, this code allows me now using Divi Builder on Custom post types so easily. Well done!

    Reply
  7. paulovsky (@paulovsky)

    thank you!

    Reply
  8. Jeff Sayre

    You can also add support for the new Divi Visual Builder in your CPTs by hooking an additional filter call to the first function above. Using your function as an example, you’d add this filter call on its own line:

    add_filter( ‘et_fb_post_types’,’sb_et_builder_post_types’ );

    Reply

Leave a Reply

Divi United

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!