How to Add Divi Builder to Custom Post Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Adding Divi Builder on Custom Post Type | |
add_filter( 'et_builder_post_types', 'hs_et_builder_post_types' ); | |
// Use ANY ONE OF THE FUNCTION BELOW | |
function hs_et_builder_post_types( $post_types ) { | |
$post_types[] = 'news'; | |
// $post_types[] = 'ANOTHER_CPT_HERE'; | |
return $post_types; | |
} | |
// OR | |
function hs_et_builder_post_types( $post_types ) { | |
$post_types_slugs = array( | |
'news', | |
'custom_post_type_slug', | |
); | |
$post_types = array_merge( $post_types, $post_types_slugs ); | |
return $post_types; | |
} | |
/* Add Divi Custom Post Meta Settings box */ | |
function hs_add_meta_boxes() { | |
foreach(get_post_types() as $pt) { | |
if (post_type_supports($pt, 'editor') and function_exists('et_single_settings_meta_box')) { | |
add_meta_box('et_settings_meta_box', __('Divi Custom Post Settings', 'Divi'), 'et_single_settings_meta_box', $pt, 'side', 'high'); | |
} | |
} | |
} | |
add_action('add_meta_boxes', 'hs_add_meta_boxes'); | |
/* Dispaly Divi Builder in correct location */ | |
function hs_admin_js() { | |
$s = get_current_screen(); | |
if(!empty($s->post_type) and $s->post_type!='page' and $s->post_type!='post') { | |
?> | |
<script> | |
jQuery(function($){ | |
$('#et_pb_layout').insertAfter($('#et_pb_main_editor_wrap')); | |
}); | |
</script> | |
<style> | |
#et_pb_layout { margin-top:20px; margin-bottom:0px } | |
</style> | |
<?php | |
} | |
} | |
add_action('admin_head', 'hs_admin_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment