How to add the Divi Builder to all Custom Post Types with one function

How to add the Divi Builder to all Custom Post Types with one function

I doubt I need to convince anyone reading this that the Divi Builder is a powerful tool. It takes the heavy lifting out of creating new posts and pages and lets us reach our design potential before hitting our technical limitations, and that’s great! But every now and then you may install a plugin or third party software that adds a post type that doesn’t support the use of the Divi Builder by default. There are workarounds of course: Elegant Themes posted a great blog about how to add the Divi Builder to custom post types, and until recently, this was my own method for doing so. It works great but if you’re regularly adding plugins for testing, or have lots of CPT’s already and don’t want to go through finding the names of them all, then this method can be laborious.

However, it does give us a good base for a slightly different method. The following function doesn’t require you to know the name of your custom post types and it doesn’t even require you to update it if you add/remove plugins that load custom post types. Instead, what it does is get a list of all CPT’s currently being loaded on a site and then adds ET’s method to each of them automatically. So essentially, if you add this into your functions.php file, you can forget about the fact that CPT’s don’t have the Divi Builder option, because now they do.

<?php
function dpb_all_post_types( $post_types ) {

$post_types = get_post_types();

if ( $post_types ) { // If there are any custom public post types.
 
 foreach ( $post_types as $post_type ) {
 $post_types[] ='$post_type';

return $post_types;
 }
}
}
add_filter( 'et_builder_post_types', 'dpb_all_post_types' );
?>

Pretty cool, right?

Stephen James

SJ is a web developer living in the coastal town of Southsea, England. He is a Divi and WordPress advocate and the founder of Divi Space.